Re: [PATCH] Clear up perlcritic 'missing return' warning

From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Mike Blackwell <maiku41(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Clear up perlcritic 'missing return' warning
Date: 2018-05-23 17:38:40
Message-ID: CAA8=A79t1=zQL6j3L5sunq1XWFy-79Rg-npB_ZhsRuVuUsqTHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, May 22, 2018 at 4:35 PM, Mike Blackwell <maiku41(at)gmail(dot)com> wrote:
> On Tue, May 22, 2018 at 3:32 AM, Michael Paquier <michael(at)paquier(dot)xyz>
> wrote:
>>
>>
>> <snip> And this
>> maps with any C code.
>
>
> The important differences here are:
> *) Declaring a C function as void prevents returning a value. The intent
> not to return a value is clear to any caller and is enforced by the
> compiler. There is no equivalent protection in Perl.
> *) Falling off the end of a C function that returns a type other than void
> has undefined results. Perl will always return the value of the last
> statement executed.
>
> Because Perl does allow returning a value without explicitly using return,
> it's easy to write code that breaks if an unwary person adds a line to the
> end of the subroutine. There's a common constructor incantation that has
> this problem. It's a real gotcha for C programmers just starting to poke
> around in Perl code.
>
> This difference also allows users of .pm modules to abuse the API of a
> method intended to be "void", if the value returned falling off the end
> happens to seem useful, leading to breakage if the method's code changes in
> the future.
>
>>
>> This is most likely going to be forgotten.
>
>
> That's what perlcritic is for. :)
>
> Mike
>

I should also point out that Mike posted on this subject back on May
11, and nobody but me replied.

And yes, the idea is that if we do this then we adopt a perlcritic
policy that calls it out when we forget.

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 Alvaro Herrera 2018-05-23 17:45:18 Re: [PATCH] Clear up perlcritic 'missing return' warning
Previous Message Tom Lane 2018-05-23 16:51:38 Re: Subplan result caching