in reply to Re: Re: variable set to 0 ? 0 : 1
in thread variable set to 0 ? 0 : 1

Well, I think we'll have to agree to disagree on this one.

The point of formatting one's code is to make the meaning clear to the reader. This reader finds:

return ( ( $status == 0 ) ? 0 : 1 ); # Readable, clear. return $status == 0 ? 0 : 1; # Confusing. Precedence?
I *think* I know what the second line does, but I'm not 100% sure. Blame my 15 years of programming in C, but I have to use brackets when I write a return statement. If that means I'm writing C in Perl, so be it.

I also like to put brackets around a conditional, to highlight that there's a logic test going on. I know that operator precedence will take care of it without brackets, but why strain my brain.

Really, this is a tempest in a teapot. My Dad had a wonderful sentence that he claimed made sense, if only it were punctuated correctly: Smith, where Jones had had had had had had had had had had had the examiner's approval. Perfectly understandable: no punctuation is necessary, is it?

--t. alex
but my friends call me T.

Replies are listed 'Best First'.
Re^4: variable set to 0 ? 0 : 1
by Flexx (Pilgrim) on Sep 07, 2002 at 12:21 UTC
    The point of formatting one's code is to make the meaning clear to the reader. (...) I *think* I know what the second line does, but I'm not 100% sure.

    Hmm.. While I agree that some extra parens do no harm, I somewhat oppose the thought that using a languages (well documented) feature is "criminal". Someone's lack of specific experience or routine or different minting (no offence here) is not the "fault" of those more experienced/differently originated [uh - if this is wrong english, someone /mgs me please]. In the end, wondering about such constructs teaches us in the long run, right?

    Then again, I actually agree with both of you... ;) While it's perfectly ok to add "markup" for your own/teammates convenience, to me it's ok, ethically, to exploit ones abilities and the abilities of the tool one is using (ahh.. well, unless you're a sniper with a precision gun).

    Smith, where Jones had had had had had had had had had had had the examiner's approval

    Well, I don't mean to be pernickety (but, hell, I am ;), but I'm not sure wether this example fits, since in that sentence punctuation is not optional. In English, for good reasons, punctuation -- especially to evade ambiguity -- is mandatory, while in Perl there are clear rules how to parse an (unambigous) term. However, I still wonder what the solution to that sentence is!? ;)

    So long,
    Flexx

      Solution:

      Smith, where Jones had had "had had", had had "had"; "had had" had had the examiner's approval.

      In other words, in the exam that they both took, in one particular question, Jones wrote "had had", and Smith wrote "had". The correct answer, according to the examiner, was Jones' "had had".

      --t. alex
      but my friends call me T.

        I, where your father had had 'had had "had had", had had "had"; "had had" had had' had 'had had "had", had had "had had"; "had had" had had'; 'had had "had had", had had "had"; "had had" had had' had had talexb's approval.... ;-P

        i.e. "I had X where your father had Y; You were expecting an answer of Y."
        X and Y are slightly different ways punctuate the original string of hads.

        -Blake