git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] CodingGuidelines: discourage arbitrary suffixes in function names

From
karthik nayak <karthik.188@gmail.com>
Date
Oct 23, 2024, 07:44 UTC
Message-ID
<CAOLa=ZTSVmpDX-Os-0fs=-t4O5bN5H=aWSdxpMTSM1-UFFvfYQ@mail.gmail.com>
In-Reply-To
<ZxfVwQxMlcJbGt5D@nand.local>
Taylor Blau <me@ttaylorr.com> writes:
Show 26 quoted lines
> On Tue, Oct 22, 2024 at 03:45:38AM -0500, karthik nayak wrote:
>> >> So, that being said, I agree that we shouldn't use arbitrary suffixes,
>> >> as these are quite hard to understand indeed and typically don't really
>> >> provide any context. So as long as we interpret this rule leniently I'm
>> >> happy with it.
>> >
>> > I am not sure here... I think that using a "_1()" suffix means that the
>> > function is processing one of a number of elements that all need to be
>> > handled similarly, but where both the processing of an individual
>> > element, and the handling of a group of elements are both complicated
>> > enough to be placed in their own function.
>>
>> The crux here is that this meaning is internalized by people who know
>> the code through in and out. But for anyone new to the project, this is
>> not evident from the naming.
>
> Right. I think that with that in mind, a good goal might be to document
> that convention to make sure that newcomers to the project can easily
> interpret what foo() and foo_1() mean. Another approach is the one you
> pursue here, which is to change the existing convention in the name of
> making the code more approachable for newcomers.
>
> Both approaches meet the same end, but the former does not involve
> changing existing conventions, but instead documenting them. That seems
> like a more reasonable path to me.
>

I would disagree though. I think some conventions even though we've been using them for a while, should be changed. I guess a good middle ground is to document current behavior while also discouraging future use. I'll add that in and push a new version.

Show 33 quoted lines
>> > It's also a helpful convention when you have a recursive function that
>> > does some setup during its initial call, but subsequent layers of
>> > recursion don't need or want to repeat that setup.
>> >
>>
>> I get the usecase of having such functions. I totally see the need, it's
>> mostly the naming that I'm trying to change.
>>
>> Let's consider two of such functions:
>>
>> 1. mark_remote_island_1: This function is called to do _some_ work on a
>> single remote island when iterating over a list.
>> 2. find_longest_prefixes_1: This is a recursive function which is used
>> to find the longest prefix.
>>
>> If you notice, both use the "_1" suffix and do different things (operate
>> on a single instance from a list vs provide recursive behavior). So the
>> user has to read the code to understand, which makes the "_1" a bit
>> confusing.
>>
>> Second, this could have instead been named:
>> 1. mark_single_remote_island: Which reads better, giving the idea that
>> we are really working on a single remote island. Whereas having a "_1"
>> doesn't easily imply the same.
>> 2. find_longest_prefixes_recursively: Which also reads better, and gives
>> a hint on how the function operates and why it is split out from the
>> base function.
>
> I don't disagree that writing "single" or "recursively" can be
> considered clearer. I think that the convention to suffix such functions
> with "_1()" is more terse, but saves characters and can avoid awkward
> line wrapping.
>
But are those pros worth the ambiguity it brings?
> Thanks,
> Taylor
- Karthik
Previous: Taylor BlauNext: Junio C Hamano
Message 6 of 15 in “CodingGuidelines: discourage arbitrary suffixes in function names”
  1. CodingGuidelines: discourage arbitrary suffixes in function namesKarthik Nayak, Oct 21, 2024
  2. Patrick SteinhardtOct 21, 2024
  3. Taylor BlauOct 21, 2024
  4. karthik nayakOct 22, 2024
  5. Taylor BlauOct 22, 2024
  6. karthik nayakOct 23, 2024
  7. Junio C HamanoOct 24, 2024
  8. Taylor BlauOct 24, 2024
  9. karthik nayakOct 22, 2024
  10. Kristoffer HaugsbakkOct 21, 2024
  11. karthik nayakOct 22, 2024
  12. CodingGuidelines: discourage arbitrary suffixes in function namesKarthik Nayak, Oct 23, 2024
  13. Taylor BlauOct 23, 2024
  14. Karthik NayakOct 23, 2024
  15. Justin ToblerOct 23, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.