Re: [PATCH] git-mv.perl: use stderr for error output and cleanup
From: Andreas Ericsson <hidden>
Date: 2016-06-15 22:42:16
Junio C Hamano wrote:
BTW, I never understood the usefulness of Statement Modifiers.
Even reading the examples in perlsyn.pod:
print "Basset hounds got long ears" if length $ear >= 10;
go_outside() and play() unless $is_raining;
seeing "do these things" upfront and then realize "ah, but that
is done only when this holds true", interrupts the flow of
understanding while reading a program by somebody else [*1*].
Here's what "Programming Perl" by O'Reilly (third edition, somewhere
around page 604) has to say about it:
---%<---%<---%<---
*) Do things the most readable way. For instance:
open(FOO, $foo) or die "Can't open $foo: $!";
is better than
die "Can't open $foo: $!" unless open(FOO, $foo);
because the second way hides the main point of the statement in a modifier.
---%<---%<---%<---
Considering the book was co-authored by Larry Wall, I'd say that's as
good as an apology.
It is worse if the Statement Modifier is a loop control. (flamebait) Compound Statements take BLOCK and people who want to do a one-liner could not do so without braces. I've always thought Statement Modifies as a lame workaround for that problem.
Most things can be done without braces, so long as one doesn't spell out the 'if'. $opt_h and usage(); -d $directory or mkdir($directory); is perfectly valid perl. This way of writing it is familiar enough for shell-scripters. Hardcore C-programmers will look twice when they see a line that so obviously looks completely wrong and will almost certainly, with some revulsion, understand it. -- Andreas Ericsson andreas.ericsson@op5.se OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231