http://qs1969.pair.com?node_id=579422


in reply to Re^3: If I was forced to program in another language, the Perl language feature I would miss most would be:
in thread If I was forced to program in another language, the Perl language feature I would miss most would be:

When code is written as

if (<expr>) { statement }

instead of

statement if <expr>;
you can mentally decipher the code in the order of control flow. That's what I prefer.

  • Comment on Re^4: If I was forced to program in another language, the Perl language feature I would miss most would be:
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: If I was forced to program in another language, the Perl language feature I would miss most would be:
by BerntB (Deacon) on Oct 21, 2006 at 21:06 UTC
    I understand that traditional argument, the point is that I was using postfix if as an idiom in specific circumstances which make my code clearer.

    I specifically asked for "a clearer way of writing things like that", but you didn't answer -- which probably means you can't see a neater way, either.

    Update: Fixed spelling and a html tag so it worked. :-)

      I prefer this, as I thought I'd already stated. :-)

      my($foo) = blah($yadda); unless( $foo ) { $foo = barf->new(); } unless( $foo ) { $foo = gazonkly(); } if ( $foo < $boo ) { return ERROR_CODE; }

      When reading this code, if I determine that $foo was set to a non-zero value greater than $boo by function blah(), I only need to read the first half of each of the subsequent lines to know they don't impact the scenario I'm considering.

      When they're written backwards to the underlying logic, I can't do that. I have to read all of each line, and then forget what I've read if it doesn't apply. That's why I don't consider the idiom any clearer when written backwards. I have to wonder: why did you think reversing tradition was a good idea in this (specific) case?

        I have to wonder: why did you think reversing tradition was a good idea in this (specific) case?
        Again, because I have made a couple of idioms out of this, so there is always this way of filling in a parameter and handle error returns.

        This might be a basic brain difference -- some people read code from left-to-right religiously on a line. I guess you are one of those. Others of us don't.

        I don't know why that isn't so important for me, at least in this case. Since I align the right side test, I can see directly from the shape of the code where the initing/error handling is done. If I can handle natural languages with irregular verbs, I can handle this idiom.

        It took me quite a while before I ever wrote with postfix if, because I was "C-damaged". (I'm not claiming you're too C/java-damaged -- I just think it is different wiring of brain visual centers, or something.)

        (Hmm.. maybe I should change habit to make it easier for you people that hate that..? :-( )