Elliot Shank via RT wrote:
Show quoted text> <URL:
http://rt.cpan.org/Ticket/Display.html?id=38646 >
>
> Michael G Schwern via RT wrote:
>> CodeLayout::ProhibitParensWithBuiltins does not make an exception for
>> built-ins used inside a ternary op. The code below illustrates:
>>
>> #!/usr/bin/perl -w
>>
>> sub foo {
>> return @_ ? gmtime($_[0]) : gmtime();
>> }
>>
>> sub bar {
>> return @_ ? gmtime $_[0] : gmtime;
>> }
>>
>> Ternary ops are complicated enough that use of parens is certainly not a
>> bad thing to clarify precedence.
>
> Part of the point of disallowing parens is to get people to learn precedence.
The stated purpose of the policy is to "reduce visual clutter" and
"disambiguate built-in functions from user functions". Not to force the user
to study every line and puzzle out precedence rules in detail.
There are complicated precedence cases where it's not worth the reader
puzzling out the precedence rules, and possibly get it wrong. It creates a
visual speed bump and a trap. It's much simpler to just throw in some
disambiguating parens. Ternary ops are one of them. You can potentially
justify using parens to disambiguate in almost any compound expression which
is why I dislike this blanket rule.
Hell, I couldn't list out the precedence table and I've been programming Perl
for 12 years!
I would not blink at: open( my $fh, "<", $file ) or die $!;
"Reducing visual clutter" varies according to circumstance [1] and thus
difficult to encode as a policy. "Disambiguating built-in functions" is of
low value and can be overridden by the more important need to clarify the
precedence of a complicated expression.
I would put in a default exemption for a built-in being used as a condition
(ternary op, if statement, etc...), and a configurable exemption for any time
a built-in is used in anything but a simple statement. C<< $thing = function
@args; >> would be simple. This would allow me to tweak the policy to allow
the programmer to decide whether reducing visual clutter or disambiguation is
more important while still enforcing the obviously undesirable case.
[1] and destroyed if you need to put in a ## no critic on that line
--
24. Must not tell any officer that I am smarter than they are, especially
if it's true.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
http://skippyslist.com/list/