Re: Propose a new function - list_is_empty - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Propose a new function - list_is_empty
Date
Msg-id 1121750.1660658637@sss.pgh.pa.us
Whole thread Raw
In response to Re: Propose a new function - list_is_empty  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Propose a new function - list_is_empty
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Aug 15, 2022 at 9:28 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> That's because the *correct* way to write it is either "alist == NIL"
>> or just "!alist".

> I think the alist == NIL (or alist != NIL) style often makes the code
> easier to read. I recommend we standardize on that one.

I have a general preference for comparing to NIL because (as Daniel
noted nearby) it reminds you of what data type you're dealing with.
However, I'm not up for trying to forbid the bare-boolean-test style
altogether.  It'd be near impossible to find all the instances;
besides which we don't insist that other pointer checks be written
as explicit comparisons to NULL --- we do whichever of those seems
clearest in context.  So I'm happy for this patch to leave either
of those existing usages alone.  I agree though that while simplifying
list_length() calls, I'd lean to using explicit comparisons to NIL.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Christoph Berg
Date:
Subject: Re: pg_receivewal and SIGTERM
Next
From: Gurjeet Singh
Date:
Subject: Re: Patch proposal: New hooks in the connection path