git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-mv.perl: use stderr for error output and cleanup

From
Andreas Ericsson <ae@op5.se>
Date
Jan 8, 2006, 00:07 UTC
Message-ID
<43C057BD.7010201@op5.se>
In-Reply-To
<7v7j9bg369.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano wrote:
Show 10 quoted lines
> 
> 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.

Show 7 quoted lines
> 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
Previous: Junio C HamanoNext: Alex Riesen
Message 13 of 14 in “git-mv.perl: use stderr for error output and cleanup”
  1. git-mv.perl: use stderr for error output and cleanupAlex Riesen, Jan 5, 2006
  2. Junio C HamanoJan 6, 2006
  3. Randal L. SchwartzJan 6, 2006
  4. Linus TorvaldsJan 6, 2006
  5. Randal L. SchwartzJan 6, 2006
  6. Linus TorvaldsJan 7, 2006
  7. Junio C HamanoJan 7, 2006
  8. Alex RiesenJan 7, 2006
  9. Junio C HamanoJan 7, 2006
  10. Alex RiesenJan 10, 2006
  11. Randal L. SchwartzJan 7, 2006
  12. Junio C HamanoJan 7, 2006
  13. Andreas EricssonJan 8, 2006
  14. Alex RiesenJan 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.