Re: Propose a new function - list_is_empty

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

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 don't think we need yet another way to spell
that, and I'm entirely not on board with replacing either of those
idioms. But if you want to get rid of overcomplicated uses of
list_length() in favor of one of those spellings, have at it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2022-08-16 01:39:25 Re: Propose a new function - list_is_empty
Previous Message Peter Smith 2022-08-16 01:19:47 Propose a new function - list_is_empty