http://qs321.pair.com?node_id=1167845


in reply to Re^3: Thoughts on using and, or, and not over && || !? (purpose)
in thread Thoughts on using and, or, and not over && || !?

The other problem with parentheses is that if you nest them more than just 2 levels, then people have a terrible time trying to match them up. Yes, I've had people tell me that they don't have a problem with that. But when I've shown such people a slide containing fairly simple code with full use of parentheses, zero of them noticed the bug I had introduced by adding the parentheses.

Yes, it is certainly possible to use 'or' in a logical expressions in a way that does not introduce a bug. (Just like it is certainly possible to use a screwdriver to hammer in a nail.) But after having found multiple bugs due to such (that made it into Production code) having been written by quite a few different developers, several of them very experienced with Perl, I don't have enough hubris to think that I have such immense intelligence and flawless care such that I can avoid such mistakes.

There are plenty of details to keep in mind when programming. Using a tool that requires you to be extra careful when you use it, yet in tons of situations causes no problems when you forget those extra steps, and then, when you actually introduce a bug because of it the bug is likely to only be triggered when a fairly specific combination of multiple conditions are met... Yeah, that sounds like a profoundly bad idea to me. And experience shows that it is.

Using 'or' or 'and' in a logical expression in Perl gives you something that looks like a logical expression. And yet it is something that, only in some situations but still quite a large variety of situations, doesn't behave like a logical expression. It is extremely easy to, in the process of dealing with all of the other details flying around when working on code, to forget that this thing that is being used as a logical expression and that looks like a logical expression is not actually an ordinary logical expression and so can surprise you.

- tye