Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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]
[Corion]: thezip: The Canary Islands - they have a constant climate
[Corion]: Maybe a bit too many old people, but for some do-nothing vacation for R&R exactly the right thing ;)=
[thezip]: That's awesome. I bet you feel totally rejuvenated and ready for the next thing.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-02-23 17:05 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (349 votes). Check out past polls.