Re: Patch to implement pg_current_logfile() function

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Gilles Darold <gilles(dot)darold(at)dalibo(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Patch to implement pg_current_logfile() function
Date: 2017-01-16 18:40:30
Message-ID: 20170116184030.xf6oicuy37hh575a@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Karl O. Pinc wrote:

> I do have a question here regards code formatting.
> The patch now contains:
>
> if (log_filepath == NULL)
> {
> /* Bad data. Avoid segfaults etc. and return NULL to caller. */
> break;
> }
>
> I'm not sure how this fits in with PG coding style,
> whether the {} should be removed or what. I've looked
> around and can't find an example of an if with a single
> line then block and a comment. Maybe this means that
> I shouldn't be doing this, but if I put the comment above
> the if then it will "run into" the comment block which
> immediately precedes the above code which describes
> a larger body of code. So perhaps someone should look
> at this and tell me how to improve it.

I think this style is good. Following the style guide to the letter
would lead to remove the braces and keep the comment where it is;
pgindent will correctly keep at its current indentation. We do use that
style in a couple of places. It looks a bit clunky. In most places we
do keep those braces, for readability and future-proofing in case
somebody inadvertently introduces another statement to the "block". We
don't automatically remove braces anyway. (We used to do that, but
stopped a few years ago shortly after introducing PG_TRY).

Putting the comment outside (above) the "if" would be wrong, too; you'd
have to rephrase the comment in a conditional tense.

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2017-01-16 18:43:59 Re: Tuple sort is broken. It crashes on simple test.
Previous Message Pavel Stehule 2017-01-16 18:38:23 Re: Tuple sort is broken. It crashes on simple test.