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

Re: [PATCH 2/2] bisect--helper: `bisect_voc` shell function in C

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
May 16, 2016, 07:49 UTC
Message-ID
<vpqlh3a1lyq.fsf@anie.imag.fr>
In-Reply-To
<1463169737-12701-2-git-send-email-pranit.bauva@gmail.com>
Pranit Bauva <pranit.bauva@gmail.com> writes:
Show 6 quoted lines
> +int bisect_voc(const char *term)
> +{
> +	if (!strcmp(term, "bad"))
> +		printf("bad|new\n");
> +	if (!strcmp(term, "good"))
> +		printf("good|old\n");

If you meant to use this as a helper command, then the implementation is right, but you're not doing that.

If you write the function because one day you'll be calling it from C, then:

1) First, I'd wait for this "one day" to happen. In general, write code
   when you need it, don't write it ahead of time. Currently, you have
   dead and untested code (I know, *you* have tested it, but it's still
   "untested" as far as git.git is concerned). Dead code may bother
   people reading the code (one would not understand why it's there),
   and untested code means it may break later without anyone noticing.
2) Second, you'd need to return the string, not print it. You'll
   typically use it like this:
     printf(_("You need to give me at least one %s and one %s"),
            bisect_voc(BISECT_BAD), bisect_voc(BISECT_GOOD));
   which gives one more argument for 1): once you have a use-case, you
   can design the API properly, and not blindly guess that you're going
   to need printf. Actually, writting these 2 example lines, I also
   noticed that the parameters could/should be an enum type rather than
   a string, it makes the code both more efficient and clearer.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Johannes SchindelinNext: Eric Sunshine
Message 8 of 10 in “bisect--helper: `bisect_log` shell function in C”
  1. 1/2 bisect--helper: `bisect_log` shell function in CPranit Bauva, May 13, 2016
  2. 2/2 bisect--helper: `bisect_voc` shell function in CPranit Bauva, May 13, 2016
  3. Pranit BauvaMay 13, 2016
  4. Johannes SchindelinMay 16, 2016
  5. Pranit BauvaMay 20, 2016
  6. Pranit BauvaMay 22, 2016
  7. Johannes SchindelinMay 23, 2016
  8. Matthieu MoyMay 16, 2016
  9. Eric SunshineMay 16, 2016
  10. Pranit BauvaMay 20, 2016

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.