lwlocknames.h beautification attempt - Mailing list pgsql-hackers

From Gurjeet Singh
Subject lwlocknames.h beautification attempt
Date
Msg-id CABwTF4VxfwDtRV-H22_XK4XeDogaV-Vaobu+af5U=8ZAZn9ZZQ@mail.gmail.com
Whole thread Raw
Responses Re: lwlocknames.h beautification attempt
Re: lwlocknames.h beautification attempt
Re: lwlocknames.h beautification attempt
List pgsql-hackers
Currently the contents of lwlocknames.h look like this:

#define ShmemIndexLock (&MainLWLockArray[1].lock)
#define OidGenLock (&MainLWLockArray[2].lock)
#define XidGenLock (&MainLWLockArray[3].lock)
#define ProcArrayLock (&MainLWLockArray[4].lock)
#define SInvalReadLock (&MainLWLockArray[5].lock)
...

This makes it a bit hard to read, since there is no attempt at vertical alignment along the opening parentheses. It gets worse if the editor performs syntax highlighting, and the various colored characters in the definitions appear haphazardly arranged.

Had this been hand-written, I can imagine the author making an attempt at aligning the definitions, but since this is a generated file, the lack of that attempt is understandable.

I propose the following change to the generation script, generate-lwlocknames.pl

-    print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
+    printf $h "#define %-30s %s\n", "${lockname}Lock", "(&MainLWLockArray[$lockidx].lock)";

which produces the lock names in this format

#define ShmemIndexLock                 (&MainLWLockArray[1].lock)
#define OidGenLock                     (&MainLWLockArray[2].lock)
#define XidGenLock                     (&MainLWLockArray[3].lock)
#define ProcArrayLock                  (&MainLWLockArray[4].lock)
#define SInvalReadLock                 (&MainLWLockArray[5].lock)
...

Yet another format, which I prefer, can be achieved by right-aligning the lock names. In addition to aligning the definitions, it also aligns the 'Lock' suffix in all the names. But as they say beauty is in the eye of the beholder, so this one may be actively disliked by others.

-    print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
+    printf $h "#define %30s %s\n", "${lockname}Lock", "(&MainLWLockArray[$lockidx].lock)";

#define                 ShmemIndexLock (&MainLWLockArray[1].lock)
#define                     OidGenLock (&MainLWLockArray[2].lock)
#define                     XidGenLock (&MainLWLockArray[3].lock)
#define                  ProcArrayLock (&MainLWLockArray[4].lock)
#define                 SInvalReadLock (&MainLWLockArray[5].lock)
...

The lockname column needs to be at least 30 chars wide to accommodate the longest of the lock names 'DynamicSharedMemoryControlLock'.

Best regards,
Gurjeet
http://Gurje.et

pgsql-hackers by date:

Previous
From: Junwang Zhao
Date:
Subject: Re: Emitting JSON to file using COPY TO
Next
From: Tom Lane
Date:
Subject: Re: lwlocknames.h beautification attempt