Making C function declaration parameter names consistent with corresponding definition names
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-09-16T22:42:13Z
Lists: pgsql-hackers
Attachments
- v1-0002-Harmonize-parameter-names-in-pg_dump-pg_dumpall.patch (application/octet-stream) patch v1-0002
- v1-0001-Harmonize-parameter-names.patch (application/octet-stream) patch v1-0001
I applied clang-tidy's readability-inconsistent-declaration-parameter-name check with "readability-inconsistent-declaration-parameter-name.Strict:true" [1] to write the attached refactoring patch series. The patch series makes parameter names consistent between each function's definition and declaration. The check made the whole process of getting everything to match straightforward. The total number of lines changed worked out at less than you might guess it would, since we mostly tend to do this already: 178 files changed, 593 insertions(+), 582 deletions(-) I have to admit that these inconsistencies are a pet peeve of mine. I find them distracting, and have a history of fixing them on an ad-hoc basis. But there are real practical arguments in favor of being strict about it as a matter of policy -- it's not *just* neatnikism. First there is a non-zero potential for bugs by allowing inconsistencies. Consider the example of the function check_usermap(), from hba.c. The bool argument named "case_insensitive" is inverted in the declaration, where it is spelled "case_sensitive". At first I thought that this might be a security bug, and reported it to -security as such. It's harmless, but is still arguably something that might have led to a real bug. Then there is the "automated refactoring" argument. It would be nice to make automated refactoring tools work a little better by always (or almost always) having a clean slate to start with. In general refactoring work might involve writing a patch that starts with the declarations that appear in a some .h file of interest in one pass, and work backwards from there. It might be necessary to switch dozens of functions over to some new naming convention or parameter order, so you really want to start with the high level interface in such a scenario. It's rather nice to be able to use clang-tidy to make sure that there are no newly introduced inconsistencies -- which have the potential to be live bugs. It's possible to use clang-tidy for this process right now, but it's not as easy as it could be because you have to ignore any preexisting minor inconsistencies. We don't quite have a clean slate to start from, which makes it more error prone. IMV there is a lot to be said for making this a largely mechanical process, with built in guard rails. Why not lean on the tooling that's widely available already? Introducing a project policy around consistent parameter names would make this easy. I believe that it would be practical and unobtrusive -- we almost do this already, without any policy in place (it only took me a few hours to come up with the patch series). I don't think that we need to create new work for committers to do this. [1] https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-inconsistent-declaration-parameter-name.html -- Peter Geoghegan
Commits
-
Harmonize parameter names in pg_dump/pg_dumpall.
- 20e69daa1348 16.0 landed
-
Harmonize parameter names in contrib code.
- 0faf7d933f62 16.0 landed
-
Harmonize more lexer function parameter names.
- 8fb4e001e9c1 16.0 landed
-
Harmonize parameter names in ecpg code.
- 3535ebce5dc5 16.0 landed
-
Harmonize lexer adjacent function parameter names.
- aab06442d488 16.0 landed
-
Harmonize more parameter names in bulk.
- a601366a460f 16.0 landed
-
Harmonize parameter names in storage and AM code.
- bfcf1b34805f 16.0 landed
-
Harmonize heapam and tableam parameter names.
- 4bac9600f09a 16.0 landed
-
Consistently use named parameters in timezone code.
- c4f8e89fef3d 16.0 landed
-
Consistently use named parameters in regex code.
- bc2187ed63c5 16.0 landed
-
Harmonize reorderbuffer parameter names.
- 035ce1feb2ed 16.0 landed
-
Make check_usermap() parameter names consistent.
- 4274dc223ce7 16.0 landed
- 1ef00afe2e45 15.0 landed
- 44933010ceb3 14.6 landed
- b7558111aba2 13.9 landed
- c1dd5a8aedc7 12.13 landed
- f01fd89b1537 11.18 landed
- 109836a14fe9 10.23 landed