Login | Register
My pages Projects Community openCollabNet

Discussions > dev > [Perl-Critic] Policy to catch overuse of short-circuit ?

perlcritic
Discussion topic

Hide all messages in topic

All messages in topic

Re: [Perl-Critic] Policy to catch overuse of short-circuit ?

Author Gabor Szabo <gabor at szabgab dot com>
Full name Gabor Szabo <gabor at szabgab dot com>
Date 2015-05-25 12:22:37 PDT
Message That is_ok is actually an indirect method call that I am also getting rid
of.

I'd start by considering any use of short-circuit which is not in a
conditional as overuse and maybe let through a few exception such as "open
or die". Or maybe those exceptions would be configurable.

Gabor


On Mon, May 25, 2015 at 10:11 PM, Jeffrey Ryan Thalhammer <jeff at thaljef dot org>
wrote:

> I’m guilty of doing that once in a while. Although mine would probably
> look like this:
>
> $node = $obj and last if is_ok $obj;
>
> In theory, your example would violate ProhibitCommaSeparat​edStatements
> <https://metacpan.org​/pod/Perl::Critic::P​olicy::ValuesAndExpr​essions::ProhibitCom​maSeparatedStatement​s>.
> But it doesn’t catch this one, probably because it doesn’t know the arity
> of is_ok.
>
> It would be very easy to write a policy that forbid multiple and and or
> in a single statement, but that is also a bit different from your example.
> You’d have to decide exactly what “overuse” means.
>
> -Jeff
> ​
>
Attachments

Re: [Perl-Critic] Policy to catch overuse of short-circuit ?

Author thaljef
Full name Jeffrey Ryan Thalhammer
Date 2015-05-25 12:12:19 PDT
Message I’m guilty of doing that once in a while. Although mine would probably look
like this:

$node = $obj and last if is_ok $obj;

In theory, your example would violate ProhibitCommaSeparat​edStatements
<https://metacpan.org​/pod/Perl::Critic::P​olicy::ValuesAndExpr​essions::ProhibitCom​maSeparatedStatement​s>.
But it doesn’t catch this one, probably because it doesn’t know the arity
of is_ok.

It would be very easy to write a policy that forbid multiple and and or in
a single statement, but that is also a bit different from your example.
You’d have to decide exactly what “overuse” means.

-Jeff
 
Attachments

[Perl-Critic] Policy to catch overuse of short-circuit ?

Author Gabor Szabo <gabor at szabgab dot com>
Full name Gabor Szabo <gabor at szabgab dot com>
Date 2015-05-25 06:53:12 PDT
Message Hi

open or die

is a fairly accepted expression, but some people really love to write in
the shell-ish way

cond and cond and action;

e.g. I just encountered this code:

    is_ok $obj and $node = $obj, last;
Is there a policy that would locate these?

regards
   Gabor
Attachments
Messages per page: