Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Burned by precedence rules

by sundialsvc4 (Abbot)
on Dec 30, 2008 at 22:17 UTC ( #733350=note: print w/ replies, xml ) Need Help??


in reply to Burned by precedence rules

“((I) parenthesize (like (crazy))) and (have (never (regretted it))),” he said bluntly, compulsively counting the left and right parentheses in his statement to be sure that they were evenly matched. “(They (cost me) nothing) and (remove (all doubt)).”

What matters ... truly the only thing that really matters ... is clarity. Anyone and everyone who looks at a line of source-code needs to be able to know, without a shred of doubt or ambiguity, what that line of source will mean to the computer. A few well-placed parentheses, as well as newlines and white-space, will help tremendously in comprehension by the humans (including yourself) who will one day “parse” the code. The cost of any mis-understanding can be huge... both in time and in real money.

I vividly remember the “programming puzzlers” that used to be put out in magazines like Dr. Dobb's by the purveyors of a certain debugging system. The objective was to read a line of cryptic code and to interpret what it actually meant. I found myself thinking, “gee, I wouldn't want to have to write 50,000 lines of real production software in that language!” (Of course, “that language” was C, and therefore of course this was what I did do for a living, but it really rammed-home the importance of simplicity and clarity.) The computer does not care, but humans (like you) do.


Comment on Re: Burned by precedence rules
Re^2: Burned by precedence rules
by ikegami (Pope) on Dec 30, 2008 at 22:59 UTC

    ( Oops, I thought that was in reply to Re^5: Burned by precedence rules )

    That's exactly my point. Those who usually treat "and" and "or" as flow control statements don't do it because they must. Like you said, the computer doesn't care. To them, it increases the clarity/readability/maintainability of the code.

Re^2: Burned by precedence rules
by BrowserUk (Pope) on Dec 31, 2008 at 01:36 UTC
    ((I) parenthesize (like (crazy))) and (have (never (regretted it))), ... (They (cost me) nothing) and (remove (all doubt)).

    If you think that having that number of parens in a single compound condition achieves clarity, may I suggest you learn lisp. You'll be right at home.

    Otherwise, there are far better ways to achieve clarity. From using whitespace, to nested ifs, to breaking sub terms out as functions with meaningful names.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://733350]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-11-21 02:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (104 votes), past polls