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

Ted Zlatanov [off-list ref] writes:
 - As in C (see above), we avoid using braces unnecessarily (but Perl
   forces braces around if/unless/else/foreach blocks, so this is not
   always possible).
Is it ever (as opposed to "not always") possible to omit braces?

It sounds as if we encourage the use of statement modifiers, which
certainly is not what I want to see.

You probably would want to mention that opening braces for
"if/else/elsif" do not sit on their own line, and closing braces for
them will be followed the next "else/elseif" on the same line
instead, but that is part of "most of the C guidelines above apply"
so it may be redundant.
 - Don't abuse statement modifiers (unless $youmust).
It does not make a useful guidance to leave $youmust part
unspecified.

Incidentally, your sentence is a good example of where use of
statement modifiers is appropriate: $youmust is rarely true.

In general:

	... do something ...
	do_this() unless (condition);
        ... do something else ...

is easier to follow the flow of the logic than

	... do something ...
	unless (condition) {
		do_this();
	}
        ... do something else ...

*only* when condition is extremely rare, iow, when do_this() is
expected to be almost always called.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help