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

Re: [PATCH] decorate: clean up and document API

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Dec 11, 2017, 18:32 UTC
Message-ID
<20171211103249.e34385be4688734442659e71@google.com>
In-Reply-To
<20171208095510.GA29626@sigill.intra.peff.net>

On Fri, 8 Dec 2017 04:55:11 -0500 Jeff King <peff@peff.net> wrote:

Show 17 quoted lines
> I have mixed feelings. On the one hand, compiling and running the code
> ensures that those things actually work. On the other hand, I expect you
> can make a much clearer example if instead of having running code, you
> show snippets of almost-code.
> 
> E.g.:
> 
>   struct decoration d = { NULL };
> 
>   add_decoration(&d, obj, "foo");
>   ...
>   str = lookup_decoration(obj);
> 
> pretty much gives the relevant overview, with very little boilerplate.
> Yes, it omits things like the return value of add_decoration(), but
> those sorts of details are probably better left to the function
> docstrings.

The part about iterating over all entries should probably also be shown too. Besides that, I'm OK with having a simplified example in documentation too, but I'll wait and see if others have any opinions before making any changes.

Show 7 quoted lines
> Other than that philosophical point, the documentation you added looks
> pretty good to me. Two possible improvements to the API we could do on
> top:
> 
>   1. Should there be a DECORATION_INIT macro (possibly taking the "name"
>      as an argument)? (Actually, the whole name thing seems like a
>      confusing and bad API design in the first place).

Agreed about the "name" thing. I'll add a DECORATION_INIT when I make the next reroll, but I think that having it with no argument is best (and instantiating "name" with NULL).

>   2. This is really just an oidmap to a void pointer. I wonder if we
>      ought to be wrapping that code (I think we still want some
>      interface so that the caller doesn't have to declare their own
>      structs).

It is slightly different from oidmap in that this uses "struct object *" as a key whereas oidmap uses "struct object_id", meaning that a user of "decorate" must already have objects allocated or be willing to allocate them, whereas a user of "oidmap" doesn't.

Having said that, it is true that perhaps we have too many data structures doing similar things.

Previous: Jeff KingNext: Jeff King
Message 3 of 4 in “decorate: clean up and document API”
  1. decorate: clean up and document APIJonathan Tan, Dec 8, 2017
  2. Jeff KingDec 8, 2017
  3. Jonathan TanDec 11, 2017
  4. Jeff KingDec 15, 2017

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.