Re: [PATCH] Implement motd for PostgreSQL

Поиск
Список
Период
Сортировка
От ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Тема Re: [PATCH] Implement motd for PostgreSQL
Дата
Msg-id 874kglq4bt.fsf@wibble.ilmari.org
обсуждение исходный текст
Ответ на Re: [PATCH] Implement motd for PostgreSQL  (Fabien COELHO <coelho@cri.ensmp.fr>)
Ответы Re: [PATCH] Implement motd for PostgreSQL
Список pgsql-hackers
Fabien COELHO <coelho@cri.ensmp.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: SP-GiST confusion: indexed column's type vs. index column type
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: Autovacuum on partitioned table (autoanalyze)