Re: pgindent versus struct members and typedefs

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, 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-03 15:35:53
Message-ID: eddf240a-05b2-4f6b-9a6e-81b0a9523353@dunslane.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2025-12-02 Tu 6:31 PM, Chao Li wrote:
>
>> On Dec 3, 2025, at 07:13, 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:51, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>> 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?
>> In my head, a comment and a statement are two lines, and so need
>> wrapping braces as much as two statements would do. I realize that
>> C compilers think differently, but for readability and modifiability
>> reasons that's the approach I take.
>>
> Totally agreed. In my first job at Lucent Technologies, the coding standard was that braces should always be added even if a clause has only one line of code. I remember one of the explanations was like, if braces has been added, then later when a new line of code is added to the clause, there is only one line of diff, otherwise braces need to be added, so it would be 3 lines of diffs.
>

+1. One of the things I find particularly un-aesthetic is having some
branches of an if statement with braces and some without. We have lots
of cases of that, but I try to avoid it.

cheers

andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-12-03 15:52:51 Re: Minor LLVM cleanups
Previous Message Andres Freund 2025-12-03 15:33:53 Re: Segmentation fault on proc exit after dshash_find_or_insert