Skip to contentSkip to conversation

CodingGuidelines: discourage arbitrary suffixes in function names

PATCH In review Karthik Nayak 2 participants 3 messages Oct 24, 2024 1 message not in the archive Documentation

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): https://lore.kernel.org/r/[email protected]

#1 lore raw

PATCH v3 1/1 CodingGuidelines: discourage arbitrary suffixes in function names

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.

---

I decided to send in a third version based on the feedback received from Justin and Junio, this version is bit less aggressive and more hopeful.

 Documentation/CodingGuidelines | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/CodingGuidelines +14 -0
index 30fda4142c..87904791cb 100644
@@ -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.

Range-diff against v2:
1: dd556a8029 ! 1: 617b8831d3 CodingGuidelines: discourage arbitrary suffixes in function names
@@ Documentation/CodingGuidelines: For C programs:
- S_free() releases a structure's contents and frees the
structure.

-+ - Function names should be self-explanatory, clearly reflecting their
-+ purpose or behavior.
++ - 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.
+
-+ The '_1' suffix for function names has historically indicated:
++ Historically, the '_1' suffix has been used in situations where:
+
-+ - functions processing one of several elements that all need to be
-+ handled similarly.
++ - A function handles one element among a group that requires similar
++ processing.
++ - A recursive function has been separated from its setup phase.
+
-+ - recursive functions that need to be separated from a setup stage.
-+
-+ To maintain clarity and avoid confusion, such arbitrary suffixes are
-+ discouraged, as they provide no meaningful insight into the function's
-+ role.
-+
-+To maintain clarity and avoid confusion,
-+ arbitrary suffixes such as _1 are discouraged, as they provide no
-+ meaningful insight into the function's role.
++ 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:

Signature · 1 line
2.47.0
#2 lore raw
Quoted 5 lines · Karthik Nayak

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.

I replied to the wrong ID, the previous versions can be found here:
https://lore.kernel.org/git/[email protected]/#t

#3 lore raw
In reply to Karthik Nayak
Quoted 7 lines · Karthik Nayak

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.

---

Thanks, I think that this version is looking quite good. Let's let it simmer a little longer so folks can continue to discuss, but I think that this is looking quite good.

Thanks,
Taylor