Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by BerntB (Deacon)
on Oct 18, 2006 at 02:52 UTC ( #578944=note: print w/ replies, xml ) Need Help??


in reply to Re^2: 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:

I mainly use it for returning error cases (as I showed) and for things like alternative initiation of variables:

... my($foo) = blah($yadda); $foo = barf->new() unless $foo; $foo = gazonkly() unless $foo; return ERROR_CODE if $foo < $boo; ...
I am not exactly known for aesthetical good taste, but I like it. If you have a clearer way of writing things like that, please tell me.


Comment on Re^3: If I was forced to program in another language, the Perl language feature I would miss most would be:
Download Code
Re^4: If I was forced to program in another language, the Perl language feature I would miss most would be:
by Anonymous Monk on Oct 19, 2006 at 17:46 UTC
    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.

      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?

Re^4: If I was forced to program in another language, the Perl language feature I would miss most would be:
by Anonymous Monk on May 30, 2008 at 15:43 UTC
    Is this what Perl's or-equals or defined-or-equals operators are for?
    $foo ||= barf->new(); $foo ||= gazonkly();
    or to only test undef:
    $foo //= barf->new(); $foo //= gazonkly();

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-10-20 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (92 votes), past polls