Re: Propose a new function - list_is_empty

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Junwang Zhao <zhjwpku@gmail.com>
Cc: Daniel Gustafsson <daniel@yesql.se>, Peter Smith <smithpb2250@gmail.com>, Robert Haas <robertmhaas@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-08-17T13:48:19Z
Lists: pgsql-hackers
Junwang Zhao <zhjwpku@gmail.com> writes:
> There are some places that add extra parenthesis like here
>   while (list_length(sortclause) > list_length(previous) &&
> -        list_length(new_elems) > 0)
> +        (new_elems != NIL))

> Is it necessary to add that extra parenthesis?

I'd drop the parens in these particular examples because they are
inconsistent with the other parts of the same "if" condition.
I concur with Daniel's point that parens can be useful as a visual
aid even when they aren't strictly necessary --- but I don't think
we should make future readers wonder why one half of the "if"
is parenthesized and the other isn't.

			regards, tom lane



Commits

  1. Avoid using list_length() to test for empty list.