Re: [PATCH] Implement motd for PostgreSQL

From: ilmari(at)ilmari(dot)org (Dagfinn Ilmari Mannsåker )
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Joel Jacobson <joel(at)compiler(dot)org>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: [PATCH] Implement motd for PostgreSQL
Date: 2021-04-04 18:42:30
Message-ID: 874kglq4bt.fsf@wibble.ilmari.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> writes:

>>> The actual source looks pretty straightforward. I'm wondering whether pg
>>> style would suggest to write motd != NULL instead of just motd.
>>
>> That's what I had originally, but when reviewing my code verifying code style,
>> I noticed the other case it more common:
>>
>> if \([a-z]* != NULL &&
>> 119 results in 72 files
>>
>> if \([a-z]* &&
>> 936 results in 311 files
>
> If other cases are indeed pointers. For pgbench, all direct "if (xxx &&"
> cases are simple booleans or integers, pointers seem to have "!=
> NULL". While looking quickly at the grep output, ISTM that most obvious
> pointers have "!= NULL" and other cases often look like booleans:
>
> catalog/pg_operator.c: if (isDelete && t->oprcom == baseId)
> catalog/toasting.c: if (check && lockmode != AccessExclusiveLock)
> commands/async.c: if (amRegisteredListener && listenChannels == NIL)
> commands/explain.c: if (es->analyze && es->timing)
> …
>
> I'm sure there are exceptions, but ISTM that the local style is "!= NULL".

Looking specifically at code checking an expression before dereferencing
it, we get:

$ ag '(?:if|Assert)\s*\(\s*(\S+)\s*&&\s*\1->\w+' | wc -l
247

$ ag '(?:if|Assert)\s*\(\s*(\S+)\s*!=\s*NULL\s*&&\s*\1->\w+' | wc -l
74

So the shorter 'foo && foo->bar' form (which I personally prefer) is
considerably more common than the longer 'foo != NULL && foo->bar' form.

- ilmari
--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2021-04-04 19:00:46 Re: ALTER TABLE ADD COLUMN fast default
Previous Message Tom Lane 2021-04-04 18:40:01 Re: SP-GiST confusion: indexed column's type vs. index column type