more useful options | |
PerlMonks |
Re: Thoughts on using and, or, and not over && || !? (purpose)by tye (Sage) |
on Jul 12, 2016 at 18:24 UTC ( [id://1167638]=note: print w/replies, xml ) | Need Help?? |
or was basically created for use in code like open ... or die .... That is why it was given extremely low precedence. It was not implemented as a "pretty" replacement for ||. So, or was meant to be used for flow control between statements while || continues to be meant for use in logical expressions. Using || for flow control between statements was often leading to bugs:
That is still an easy bug to introduce, so you should use or for such. So it should be no surprise that you can easily introduce bugs by using or for building logical expressions. In fact, I've seen quite a few bugs from quite a few different highly experienced Perl developers due to the use of or (or and) for building logical expressions. They didn't even realize that they had introduced the bugs. So, perhaps you are just way better than all of those highly experienced Perl developers I've worked with. Maybe, the people who say "I've never made such mistakes" are actually correct in their assessment despite the multiple examples of people who thought they had not made that mistake until I pointed it out to them. So I discourage people from using or for what || was designed for and vice-versa. No bug:
Bug easily introduced:
No warning generated. Lots of different ways to make that same mistake. Hammers are ungainly and weirdly shaped. Screwdrivers are sleek and cylindrical. I pound nails in with screwdrivers because I think it makes the act of pounding in nails easier on the eyes. Some people think I'm silly for choosing my tools based on style considerations over how the tools were designed to be used. But I've never had problems with the nails I've pounded in, so what do they know? - tye
In Section
Seekers of Perl Wisdom
|
|