Re: cleaning perl code

From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cleaning perl code
Date: 2020-04-11 17:01:54
Message-ID: 52405073-d836-6edb-b09a-681c59d18387@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 4/11/20 12:48 PM, Tom Lane wrote:
> Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com> writes:
>> On 4/11/20 12:30 AM, Noah Misch wrote:
>>> In summary, among those warnings, I see non-negative value in "Code before
>>> warnings are enabled" only. While we're changing this, I propose removing
>>> Subroutines::RequireFinalReturn. Implicit return values were not a material
>>> source of PostgreSQL bugs, yet we've allowed this to litter our code:
>> That doesn't mean it won't be a source of problems in future, I've
>> actually been bitten by this in the past.
> Yeah, as I recall, the reason for the restriction is that if you fall out
> without a "return", what's returned is the side-effect value of the last
> statement, which might be fairly surprising. Adding explicit "return;"
> guarantees an undef result. So when this does prevent a bug it could
> be a pretty hard-to-diagnose one. The problem is that it's a really
> verbose/pedantic requirement for subs that no one ever examines the
> result value of.
>
> Is there a way to modify the test so that it only complains when
> the final return is missing and there are other return(s) with values?
> That would seem like a more narrowly tailored check.
>
>

Not AFAICS:
<https://metacpan.org/pod/Perl::Critic::Policy::Subroutines::RequireFinalReturn>

That would probably require writing a replacement module. Looking at the
source if this module I think it might be possible, although I don't
know much of the internals of perlcritic.

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2020-04-11 17:27:58 Re: cleaning perl code
Previous Message Alvaro Herrera 2020-04-11 16:56:47 Re: range_agg