http://www.perlmonks.org?node_id=728101


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.