Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: Code Maintainability

by Porculus (Hermit)
on Dec 04, 2008 at 21:07 UTC ( #728101=note: print w/ replies, xml ) Need Help??

in reply to Re: Code Maintainability
in thread Code Maintainability

The other thing about statement modifiers is they make it harder to add stuff to the condition. (...)

If it were written as three lines to begin with, I wouldn't have to go through so much trouble to add the one extra action.

Sometimes "maintainability" is about "editability" rather than "readability".

Editability is about using a decent editor. For example, in Emacs you can convert between block "if" and statement-modifier "if" with a single command. If your editor can't do that, then I would argue it's your editor's problem...

As an aside, this looks clumsy to me:

print STDERR join("\n", @lines), "\n";

I've sometimes written that as:

print STDERR map { "$_\n" } @lines;

I wouldn't use either form; they both get too far away from mpeever's ideal, which I share, of code that reads like English.

If you want to print a bunch of lines to STDERR, I personally believe it's best to say "I want to print a bunch of lines", not "I want to build a string by joining a bunch of lines with newline characters, and then print that" or "I want to map a bunch of lines to a new array where they're terminated with newline characters, and then print that". In other words, I'd write:

print STDERR "$_\n" for @lines;

or, better still,

say STDERR $_ for @lines;

if you're lucky enough to have an up-to-date Perl, which of course many of us don't, in the workplace.

Comment on Re^2: Code Maintainability
Select or Download Code
Re^3: Code Maintainability
by mpeever (Friar) on Dec 05, 2008 at 20:18 UTC

    In other words, I'd write:
    print STDERR "$_\n" for @lines;
    I think you're right: that's the clear winner. It's much less cryptic, and doesn't seem to offer any real downsides.

      { local $, = "\n"; say STDERR @lines; }
      be clearer still?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-08-22 08:12 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (150 votes), past polls