Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Two simple code style advice questions

by BrowserUk (Pope)
on Jan 16, 2013 at 14:43 UTC ( #1013585=note: print w/replies, xml ) Need Help??


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

OK defined as 0? Yuck!

That's as bad as defining TRUE as 0.

It would be far clearer as:

use constant NOERROR => 0; my $errstr = ( $case != NOERROR ? $msg[$case] : "" );

Though I'd skip that conditional statement completely and embed the logic in the data:

$msg[ 0 ] = ''; ... 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.

Replies are listed 'Best First'.
Re^3: Two simple code style advice questions
by blue_cowdawg (Monsignor) on Jan 16, 2013 at 14:50 UTC
        OK defined as 0? Yuck!

    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
      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.

      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.
      Why even bother defining a constant ;)
      no warnings; if (0 == OK) { print 'Everything is ok here!'; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013585]
help
Chatterbox?
[LanX]: Corion: come on, people are people! ;)
[Corion]: Naah, I think it's still an OK show so far. Their new songs aren't exactly great, but I'm not going there for new material anyway ;)
[marto]: I got the feeling from the last show that for big sections of it, they were not really into what they were doing
[Corion]: LanX: Sure, they can bask in my Halo
[marto]: more so than the previous show I saw
[Corion]: marto: Well, I think they go a tour every two years and I think it's hard to even get a connection with the crowd at a 20k people concert... But maybe after this time I'll stop too ;)
[Corion]: I still have to see the Pet Shop Boys live before they stop touring at all
[marto]: yeah, I think that as a group creatively they're done. I can understand how it'd be hard to stop the process, album/tour, album/tour, if that's pretty much all you've ever done :)
[marto]: Corion yes I saw them Pandemonium_Tour
[Corion]: marto: Yeah, and I doubt that they'll ever get back to something like Violator/Songs of Faith and Devotion - it would either alienate their "regular" crowd, or be "too much Violator" ;)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2017-03-24 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.