Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Code Maintainability

by jeffa (Bishop)
on Dec 04, 2008 at 16:23 UTC ( #728019=note: print w/replies, xml ) Need Help??

in reply to Code Maintainability

Wonderful stuff. :) I only have one gripe and that's with the following:

if ($DEBUG) { print STDERR "Debug: some value"; } [download] is pretty clear, but if we re-write that one line, it becomes more of +a conversation with the maintainer: print STDERR "Debug: some value" if $DEBUG;

I do agree that the second line reads like English ... but it doesn't scale well. Consider this:

if ($DEBUG) { print STDERR "Debug: some value"; # some tempory line to debug our debuger ... # some other temp line ... }

The difference is to never use one line for such if statements because sooner or later you are going to want to put another line in the block. Even if it's just temporary, you are going to have to rewrite the second line so you might as well accept that all if blocks will always take up at least 3 lines. I have adopted this practice for about a year now and it has served me very very well. YMMV naturally. Great mediation man! :)


(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Code Maintainability
by JadeNB (Chaplain) on Dec 09, 2008 at 18:30 UTC
    if ($DEBUG) { print STDERR "Debug: some value"; # some tempory line to debug our debuger ... # some other temp line ... }
    I think that Perlers have a (probably appropriate) inclination against do blocks; but of course one can (as jkva points out below) have the multi-line cake and eat it too (or something):
    do { print STDERR "Debug: some value"; # some temporary line # some other temporary line } if $DEBUG;
    Of course, a trailing modifier after 17 lines of code isn't going to do anything for readability; but I think that do this; that if DEBUG is still reasonably English-like. As an added bonus, it's easy to transform a do-with-trailing-if to a leading if when the block gets too big and readability suffers.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728019]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-07-18 20:45 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (395 votes). Check out past polls.