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        


In reply to Re^4: Thoughts on using and, or, and not over && || !? (care) by tye
in thread Thoughts on using and, or, and not over && || !? by Argel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.