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

Re: [PATCH 2/5] roaring.[ch]: apply Git specific changes to the roaring API

From
Derrick Stolee <derrickstolee@github.com>
Date
Sep 20, 2022, 12:19 UTC
Message-ID
<990f84f9-fdd9-0d0a-4fc0-d0dbd19ee5a9@github.com>
In-Reply-To
<xmqqr10781lx.fsf@gitster.g>
On 9/19/2022 6:02 PM, Junio C Hamano wrote:
Show 27 quoted lines
> Derrick Stolee <derrickstolee@github.com> writes:
> 
>>>  int32_t array_container_write(const array_container_t *container, char *buf);
>>> +
>>> +int array_container_network_write(const array_container_t *container,
>>> +				  int (*write_fn) (void *, const void *, size_t),
>>> +				  void *data);
>>
>> Should we make write_fn a defined type? I'm not sure I've seen this
>> implicit type within a function declaration before.
> 
> Unless we can point out why having a named type is a good idea
> (e.g. we add such a function pointer as a member of a struct, or we
> keep a variable of that type somewhere), I actually would prefer to
> do without them.
> 
> Perhaps there are some more important reasons I am missing why we
> often come up with explicit types for callback function pointers in
> many parts of our API, but if there aren't, my preference actually
> is to lose them, not add more of them.
> 
> Hmph.... could "a typedef can become a place to give definitive
> documentation for the class of callback functions" be a good reason
> why we would want one?  I dunno.
> 
> In the posted patch, readers cannot tell what kind of three
> parameters they are supposed to give to write_fn().

This is exactly my reasoning. Having a clear definition gives us an opportunity to document what each parameter is for, even if it is just a variable name.

This anonymous type is used in multiple places, so it can be helpful to know that the type is connected across call sites or a stack of method calls.

In the unlikely event that we needed to modify this callback signature, changing it in one place makes it clear that we cover all connected uses instead of tracking all of these anonymous functions across multiple methods.

Thanks, -Stolee

Previous: Junio C HamanoNext: Abhradeep Chakraborty
Message 7 of 25 in “[RFC] introduce Roaring bitmaps to Git”
  1. 0/5 [RFC] introduce Roaring bitmaps to GitAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  2. 1/5 reachability-bitmaps: add CRoaring library to GitAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  3. 4/5 roaring: introduce a new config option for roaring bitmapsAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  4. 2/5 roaring.[ch]: apply Git specific changes to the roaring APIAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  5. Derrick StoleeSep 19, 2022
  6. Junio C HamanoSep 19, 2022
  7. Derrick StoleeSep 20, 2022
  8. Abhradeep ChakrabortySep 20, 2022
  9. Junio C HamanoSep 21, 2022
  10. Abhradeep ChakrabortySep 20, 2022
  11. 3/5 roaring: teach Git to write roaring bitmapsAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  12. Junio C HamanoSep 30, 2022
  13. Abhradeep ChakrabortySep 30, 2022
  14. Abhradeep ChakrabortyOct 30, 2022
  15. Derrick StoleeOct 30, 2022
  16. Abhradeep ChakrabortyOct 31, 2022
  17. Junio C HamanoOct 31, 2022
  18. C99 -> C11 or C17? (was: [PATCH 3/5] roaring: teach Git to write roaring bitmaps)Ævar Arnfjörð Bjarmason, Oct 31, 2022
  19. rsbecker@nexbridge.comOct 31, 2022
  20. Abhradeep ChakrabortyNov 1, 2022
  21. 5/5 roaring: teach Git to read roaring bitmapsAbhradeep Chakraborty via GitGitGadget, Sep 19, 2022
  22. Derrick StoleeSep 19, 2022
  23. Abhradeep ChakrabortySep 20, 2022
  24. Taylor BlauSep 20, 2022
  25. Abhradeep ChakrabortySep 21, 2022

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.