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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 24, 2024, 00:50 UTC
Message-ID
<xmqqr086pbna.fsf@gitster.g>
In-Reply-To
<ZxfVwQxMlcJbGt5D@nand.local>
Taylor Blau <me@ttaylorr.com> writes:
> 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.

I am reasonably sure that I was the first user of the _1() convention, or at least I was one of them. The reason for the choice of suffix was only because there wasn't anything suitable when refactoring an existing function foo() into a set-up part and its recursive body, so I just kept the set-up part and the single call into the new function in the original foo(), and had to give a name to the new function that holds the body of the original logic that was moved from foo().

Neither foo_helper() or foo_recursive() were descriptive enough to warrant such longer suffixes than a simple _1(). They easily can get "help by doing what?" and "recursively doing what?" reaction, which is a sure sign that the suffixes are not descriptive enough.

That was the only reason why I picked that "short-and-sweet but cryptic" suffix.

Surely all of _1(), _helper(), _recursive() are meaningless. If we were to replace existing uses of them, the replacement has to be 10x better.

Having said all that, as an aspirational goal, I think it is good to encourage people to find a name that is descriptive when writing a new function. I'd refrain from judging if it is way too obvious to be worth documenting (as I am officially on vacation and shouldn't be thinking too much about the project).

Thanks.
Previous: karthik nayakNext: Taylor Blau
Message 7 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.