Acceptable/Best formatting of callbacks (for pluggable storage)

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Acceptable/Best formatting of callbacks (for pluggable storage)
Date: 2019-01-11 04:45:07
Message-ID: 20190111044507.3ntgnzsajsx7pn6z@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The pluggable storage patchset has a large struct full of callbacks, and
a bunch of wrapper functions for calling those callbacks. While
starting to polish the patchset, I tried to make the formatting nice.

By default pgindent yields formatting like:

/*
* API struct for a table AM. Note this must be allocated in a
* server-lifetime manner, typically as a static const struct, which then gets
* returned by FormData_pg_am.amhandler.
*/
typedef struct TableAmRoutine
{
NodeTag type;

...
void (*relation_set_new_filenode) (Relation relation,
char persistence,
TransactionId *freezeXid,
MultiXactId *minmulti);

...

static inline void
table_set_new_filenode(Relation rel, char persistence,
TransactionId *freezeXid, MultiXactId *minmulti)
{
rel->rd_tableam->relation_set_new_filenode(rel, persistence,
freezeXid, minmulti);
}

which isn't particularly pretty, especially because there's callbacks
with longer names than the example above.

Unfortunately pgindent prevents formatting the callbacks like:
void (*relation_set_new_filenode) (
Relation relation,
char persistence,
TransactionId *freezeXid,
MultiXactId *minmulti);

or something in that vein. What however does work, is:

void (*relation_set_new_filenode)
(Relation relation,
char persistence,
TransactionId *freezeXid,
MultiXactId *minmulti);

I.e. putting the opening ( of the parameter list into a separate line
yields somewhat usable formatting. This also has the advantage that the
arguments of all callbacks line up, making it a bit easier to scan.

Similarly, to reduce the indentation, especially for callbacks with long
names and/o with longer paramter names, we can do:

static inline void
table_set_new_filenode(Relation rel, char persistence,
TransactionId *freezeXid, MultiXactId *minmulti)
{
rel->rd_tableam->relation_set_new_filenode
(rel, persistence, freezeXid, minmulti);
}

So, putting the parameter list, both in use and declaration, entirely
into a new line yields decent formatting with pgindent. But it's kinda
weird. I can't really come up with a better alternative, and after a
few minutes it looks pretty reasonable.

Comments? Better alternatives?

Greetings,

Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2019-01-11 04:46:09 Re: Query with high planning time at version 11.1 compared versions 10.5 and 11.0
Previous Message Dilip Kumar 2019-01-11 04:09:28 Re: Undo worker and transaction rollback