Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: CodingGuidelines Perl amendment

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:04

demerphq [off-list ref] writes:
As you mention below statement modifiers have their place. For instance

  next if $whatever;

Is considered preferable to

if ($whatever) {
  next;
}

Similarly

open my $fh, ">", $filename
   or die "Failed to open '$filename': $!";

Is considered preferable by most Perl programmers to:

my $fh;
if ( not open $fh, ">", $filename ) {
  die "Failed to open '$filename': $!";
}
Yeah, and that is for the same reason.  When you are trying to get a
birds-eye view of the codeflow, the former makes it clear that "we
do something, and then we open, and then we ...", without letting
the error handling (which also is rare case) distract us.
"unless" often leads to maintenance errors as the expression gets more
complicated over time,...
That might also be true, but my comment was not an endorsement for
(or suggestion against) use of unless.  I was commenting on
statement modifiers, which some people tend to overuse (or abuse)
and make the resulting code harder to follow.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help