http://www.perlmonks.org?node_id=1013586


in reply to Re^2: Two simple code style advice questions
in thread Two simple code style advice questions

It would seem to me that most Unix commands return 0 when things are "OK." So.. if you want to accuse me of showing my C programming roots, I plead guily.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
  • Comment on Re^3: Two simple code style advice questions

Replies are listed 'Best First'.
Re^4: Two simple code style advice questions
by runrig (Abbot) on Jan 16, 2013 at 18:53 UTC
    It would seem to me that most Unix commands return 0 when things are "OK."

    BUT, (and I'm still trying to get the developers here to overcome this), in shell programming, zero IS true (e.g. consider && and || in things like cmd1 && cmd2 or cmd1 || cmd2, and Perl is not shell.

Re^4: Two simple code style advice questions
by BrowserUk (Patriarch) on Jan 16, 2013 at 15:33 UTC
    It would seem to me that most Unix commands return 0 when things are "OK." So.. if you want to accuse me of showing my C programming roots, I plead guily.

    I understand the derivation, but still, the bland token OK has always suggested TRUE to me, and always will.

    Hence my suggested alternative of use constant NOERROR => 0; which seems less likely to cause confusion.

    That said, I wouldn't define a constant for 0 at all. It simply isn't necessary to compare against zero in Perl. The clearest idiom is simply:

    my $errstr = $case ? $msg[ $case ] : '';

    But I'd still prefer setting $msg[ 0 ] == ''; and simply:

    my $errstr = $msg[ $case ];

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.
Re^4: Two simple code style advice questions
by Anonymous Monk on Jan 16, 2013 at 15:01 UTC
    Why even bother defining a constant ;)
    no warnings; if (0 == OK) { print 'Everything is ok here!'; }