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

From Robert Haas
Subject Re: Propose a new function - list_is_empty
Date
Msg-id CA+TgmoZ+jpcHBK_rLDJEco6384hsoXw3_orsRP2jmfGdfFX8qQ@mail.gmail.com
Whole thread Raw
In response to Re: Propose a new function - list_is_empty  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Propose a new function - list_is_empty
List pgsql-hackers
On Mon, Aug 15, 2022 at 9:28 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Peter Smith <smithpb2250@gmail.com> writes:
> > During a recent code review I was going to suggest that some new code
> > would be more readable if the following:
> > if (list_length(alist) == 0) ...
>
> > was replaced with:
> > if (list_is_empty(alist)) ...
>
> > but then I found that actually no such function exists.
>
> 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.

-- 
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Propose a new function - list_is_empty
Next
From: Tom Lane
Date:
Subject: Re: Move NON_EXEC_STATIC from c.h