Re: pgindent versus struct members and typedefs

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Rahila Syed <rahilasyed90(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgindent versus struct members and typedefs
Date: 2025-12-02 23:06:45
Message-ID: 5E70CB69-1E2D-471B-8CF8-83205E5E14CE@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Dec 3, 2025, at 06:51, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> writes:
>> On Dec 3, 2025, at 06:00, Nathan Bossart <nathandbossart(at)gmail(dot)com> wrote:
>>> I tried to fix pgindent for a few, but the code is basically impenetrable.
>>> I didn't find any fixes upstream [0], either. As noted above, we could
>>> also fix it by avoiding the naming conflicts. However, I can't imagine
>>> that's worth the churn, and I've already spent way too much time on this,
>>> so IMHO the best thing to do here is nothing.
>
>> I think that’s fine.
>
> Agreed, not worth the trouble to fool with.
>
>> Actually I see the other problem with pgindent, where if a “else” clause contains a multiple-line comment and a single statement without braces, for example:
>> ...
>> I tried to fix but failed. For that problem, a solution is to add braces to the “else” clause.
>
> In this case, I think pgindent is indirectly enforcing good style.
> I do not like omitting braces around anything that's more than one
> line; readers have to pay close attention to whether the code is
> doing what it was intended to.
>

For “one line”, do you mean only a single line of statement or one line statement plus one line comment?

To clarify the pgindnet problem, if we have a one-line comment plus one-line statement, for example:
```
else
/* one line comment */
printf(…);
```

In this case, pgindent will not add an empty line after “else”.

But I totally agree with you, when there is a multiple-line comment and a single statement, it's a good habit to add braces.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-12-02 23:13:16 Re: pgindent versus struct members and typedefs
Previous Message Tom Lane 2025-12-02 22:51:15 Re: pgindent versus struct members and typedefs