pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
To: Mark Dilger <mark.dilger@enterprisedb.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: cleaning perl code
Date: Sat, 11 Apr 2020 12:47:55 -0400
Message-ID: <5b2ae2b0-8b09-d153-275a-24e7b2ac7989@2ndQuadrant.com> (raw)
In-Reply-To: <97813D8D-F185-4998-8CF8-5678746E7DEE@enterprisedb.com>
References: <e56f6fb6-38d5-8450-577c-24eb5d63f2e1@2ndQuadrant.com>
	<20200411043014.GA590991@rfd.leadboat.com>
	<0a4406d5-b428-4831-8ed9-c36764360f57@2ndQuadrant.com>
	<97813D8D-F185-4998-8CF8-5678746E7DEE@enterprisedb.com>


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 this effort:


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 feel terribly strongly about it, but personally I just about
never use the low precendence operators, and mostly prefer to resolve
precedence issue with parentheses.


>
>> 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?"

In the cases we actually have there isn't even any shorthand advantage
like this. There are only a couple of cases.


cheers


andrew

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






view thread (34+ messages)  latest in thread

Message-ID: <5b2ae2b0-8b09-d153-275a-24e7b2ac7989@2ndQuadrant.com>
Permalink:  ../5b2ae2b0-8b09-d153-275a-24e7b2ac7989@2ndQuadrant.com/
Also on:    postgresql.org/message-id/5b2ae2b0-8b09-d153-275a-24e7b2ac7989@2ndQuadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: andrew.dunstan@2ndquadrant.com, mark.dilger@enterprisedb.com, noah@leadboat.com
  Subject: Re: cleaning perl code
  In-Reply-To: <5b2ae2b0-8b09-d153-275a-24e7b2ac7989@2ndQuadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox