Re: cleaning perl code - Mailing list pgsql-hackers

From Mark Dilger
Subject Re: cleaning perl code
Date
Msg-id 4FFD55FA-0728-4DC3-AF93-0246FE555C10@enterprisedb.com
Whole thread Raw
In response to Re: cleaning perl code  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
Responses Re: cleaning perl code  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

> On Apr 11, 2020, at 9:47 AM, Andrew Dunstan <andrew.dunstan@2ndquadrant.com> wrote:
>
>
> On 4/11/20 12:28 PM, Mark Dilger wrote:
>>
>>> On Apr 11, 2020, at 9:13 AM, Andrew Dunstan <andrew.dunstan@2ndquadrant.com> wrote:
>> Hi Andrew.  I appreciate your interest and efforts here.  I hope you don't mind a few questions/observations about
thiseffort: 
>
>
> Not at all.
>
>
>>
>>> The
>>> last one fixes the mixture of high and low precedence boolean operators,
>> I did not spot examples of this in your diffs, but I assume you mean to prohibit conditionals like:
>>
>>    if ($a || $b and $c || $d)
>>
>> As I understand it, perl introduced low precedence operators precisely to allow this.  Why disallow it?
>
>
> The docs say:
>
>
>    Conway advises against combining the low-precedence booleans ( |and
>    or not| ) with the high-precedence boolean operators ( |&& || !| )
>    in the same expression. Unless you fully understand the differences
>    between the high and low-precedence operators, it is easy to
>    misinterpret expressions that use both. And even if you do
>    understand them, it is not always clear if the author actually
>    intended it.
>
>    |next| |if| |not ||$foo| ||| ||$bar||;  ||#not ok|
>    |next| |if| |!||$foo| ||| ||$bar||;     ||#ok|
>    |next| |if| |!( ||$foo| ||| ||$bar| |); ||#ok|

I don't think any of those three are ok, from a code review perspective, but it's not because high and low precedence
operatorswere intermixed. 

>>
>>> and the use of commas to separate statements
>> I don't understand the prejudice against commas used this way.  What is wrong with:
>>
>>    $i++, $j++ if defined $k;
>>
>> rather than:
>>
>>    if (defined $k)
>>    {
>>        $i++;
>>        $j++;
>>    }
>>
>
>
> I don't think the example is terribly clear. I have to look at it and
> think "Does it do $i++ if $k isn't defined?"

It works like the equivalent C-code:

    if (k)
        i++, j++;

which to my eyes is also fine.

I'm less concerned with which perlcritic features you enable than I am with accidentally submitting perl which looks
fineto me but breaks the build.  I mostly use perl from within TAP tests, which I run locally before submission to the
project. Can your changes be integrated into the TAP_TESTS makefile target so that I get local errors about this stuff
andcan fix it before submitting a regression test to -hackers? 

—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company






pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: cleaning perl code
Next
From: Tom Lane
Date:
Subject: Re: cleaning perl code