]> git.ipfire.org Git - thirdparty/git.git/commitdiff
CodingGuidelines: discourage arbitrary suffixes in function names
authorKarthik Nayak <karthik.188@gmail.com>
Thu, 24 Oct 2024 10:53:57 +0000 (12:53 +0200)
committerTaylor Blau <me@ttaylorr.com>
Thu, 24 Oct 2024 16:51:30 +0000 (12:51 -0400)
We often name functions with arbitrary suffixes like `_1` as an
extension of another existing function. This creates confusion and
doesn't provide good clarity into the functions purpose. Let's document
good function naming etiquette in our CodingGuidelines.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Documentation/CodingGuidelines

index 30fda4142ca1b375101dbe6f5af1cf383fbc5f18..87904791cbcea6e57d0fb3c7d4e27f2b0d80b95f 100644 (file)
@@ -621,6 +621,20 @@ For C programs:
     - `S_free()` releases a structure's contents and frees the
       structure.
 
+ - Function names should be clear and descriptive, accurately reflecting
+   their purpose or behavior. Arbitrary suffixes that do not add meaningful
+   context can lead to confusion, particularly for newcomers to the codebase.
+
+   Historically, the '_1' suffix has been used in situations where:
+
+   - A function handles one element among a group that requires similar
+     processing.
+   - A recursive function has been separated from its setup phase.
+
+   The '_1' suffix can be used as a concise way to indicate these specific
+   cases. However, it is recommended to find a more descriptive name wherever
+   possible to improve the readability and maintainability of the code.
+
 For Perl programs:
 
  - Most of the C guidelines above apply.