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

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.

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-21 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (105 votes), past polls