Acceptable/Best formatting of callbacks (for pluggable storage) - Mailing list pgsql-hackers

From Andres Freund
Subject Acceptable/Best formatting of callbacks (for pluggable storage)
Date
Msg-id 20190111044507.3ntgnzsajsx7pn6z@alap3.anarazel.de
Whole thread Raw
Responses Re: Acceptable/Best formatting of callbacks (for pluggable storage)  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Acceptable/Best formatting of callbacks (for pluggable storage)  (Robert Haas <robertmhaas@gmail.com>)
List 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


pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: Undo worker and transaction rollback
Next
From: Amit Langote
Date:
Subject: Re: Query with high planning time at version 11.1 compared versions10.5 and 11.0