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

Re: [PATCH] strvec: use correct member name in comments

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 12, 2024, 21:47 UTC
Message-ID
<xmqqjzoe8br0.fsf@gitster.g>
In-Reply-To
<owlyo7dqig1w.fsf@fine.c.googlers.com>
Linus Arver <linusa@google.com> writes:
> Side note: should we start naming the parameters in strvec.h? I would
> think that it wouldn't hurt at this point (as the API is pretty stable).
> If you think that's worth it, I could reroll to include that in this
> series (and also improve my commit message for this patch).

I am not sure if it adds more value to outweigh the cost of churning. When the meaning of the parameters are obvious only by looking at their types, a prototype without parameter names is easier to maintain, by allowing the parameters to be renamed only once in the implementation. When the meaning of parameters are not obvious from their types, we do want them to be named so that you only have to refer to the header files to know the argument order.

"void *calloc(size_t, size_t)" would not tell us if we should pass the size of individual element or the number of elements first, and writing "void *calloc(size_t nmemb, size_t size)" to make it more obvious is a good idea.

On the other hand, "void *realloc(void *, size_t)" is sufficient to tell us that we are passing a pointer as the first parameter and the desired size as the second parameter, without them having any name.

Are there functions declared in strvec.h you have in mind that their parameters are confusing and hard to guess what they mean?

Thanks.
Previous: Linus ArverNext: Linus Arver
Message 4 of 7 in “strvec: use correct member name in comments”
  1. strvec: use correct member name in commentsLinus Arver via GitGitGadget, Jan 12, 2024
  2. Jeff KingJan 12, 2024
  3. Linus ArverJan 12, 2024
  4. Junio C HamanoJan 12, 2024
  5. Linus ArverJan 13, 2024
  6. Jeff KingJan 13, 2024
  7. Linus ArverJan 14, 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.