git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names
       [not found] <https://lore.kernel.org/r/20241021124145.636561-1-karthik.188@gmail.com>
@ 2024-10-24 10:53 ` Karthik Nayak
  2024-10-24 11:02   ` karthik nayak
  2024-10-24 16:50   ` Taylor Blau
  0 siblings, 2 replies; 3+ messages in thread
From: Karthik Nayak @ 2024-10-24 10:53 UTC (permalink / raw)
  To: karthik.188; +Cc: git, ps, me, kristofferhaugsbakk, jltobler

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>
---

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(+)

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 30fda4142c..87904791cb 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -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:
      
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names
  2024-10-24 10:53 ` [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names Karthik Nayak
@ 2024-10-24 11:02   ` karthik nayak
  2024-10-24 16:50   ` Taylor Blau
  1 sibling, 0 replies; 3+ messages in thread
From: karthik nayak @ 2024-10-24 11:02 UTC (permalink / raw)
  Cc: git, ps, me, kristofferhaugsbakk, jltobler

[-- Attachment #1: Type: text/plain, Size: 462 bytes --]

Karthik Nayak <karthik.188@gmail.com> writes:

> 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/20241021124145.636561-1-karthik.188@gmail.com/#t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names
  2024-10-24 10:53 ` [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names Karthik Nayak
  2024-10-24 11:02   ` karthik nayak
@ 2024-10-24 16:50   ` Taylor Blau
  1 sibling, 0 replies; 3+ messages in thread
From: Taylor Blau @ 2024-10-24 16:50 UTC (permalink / raw)
  To: Karthik Nayak; +Cc: git, ps, kristofferhaugsbakk, jltobler

On Thu, Oct 24, 2024 at 12:53:57PM +0200, Karthik Nayak wrote:
> 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>
> ---

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-24 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <https://lore.kernel.org/r/20241021124145.636561-1-karthik.188@gmail.com>
2024-10-24 10:53 ` [PATCH v3] CodingGuidelines: discourage arbitrary suffixes in function names Karthik Nayak
2024-10-24 11:02   ` karthik nayak
2024-10-24 16:50   ` Taylor Blau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).