Re: Propose a new function - list_is_empty

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Propose a new function - list_is_empty
Date: 2022-08-16 13:47:56
Message-ID: CA+TgmoZ+jpcHBK_rLDJEco6384hsoXw3_orsRP2jmfGdfFX8qQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 15, 2022 at 9:28 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Peter Smith <smithpb2250(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-16 13:50:23 Re: Move NON_EXEC_STATIC from c.h
Previous Message Tom Lane 2022-08-16 13:37:51 Re: Propose a new function - list_is_empty