Re: CodingGuidelines Perl amendment
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 6, 2013, 16:29 UTC
- Message-ID
- <7vvca5mmmt.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <871ucto4vj.fsf_-_@lifelogs.com>
Ted Zlatanov <tzz@lifelogs.com> 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.