All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: Pranit Bauva <pranit.bauva@gmail.com>
Cc: git@vger.kernel.org, christian.couder@gmail.com,
	chriscool@tuxfamily.org, larsxschneider@gmail.com
Subject: Re: [PATCH 2/2] bisect--helper: `bisect_voc` shell function in C
Date: Mon, 16 May 2016 09:49:33 +0200	[thread overview]
Message-ID: <vpqlh3a1lyq.fsf@anie.imag.fr> (raw)
In-Reply-To: <1463169737-12701-2-git-send-email-pranit.bauva@gmail.com> (Pranit Bauva's message of "Sat, 14 May 2016 01:32:17 +0530")

Pranit Bauva <pranit.bauva@gmail.com> writes:

> +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/

  parent reply	other threads:[~2016-05-16  7:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 20:02 [PATCH 1/2] bisect--helper: `bisect_log` shell function in C Pranit Bauva
2016-05-13 20:02 ` [PATCH 2/2] bisect--helper: `bisect_voc` " Pranit Bauva
2016-05-13 20:07   ` Pranit Bauva
2016-05-16  6:40   ` Johannes Schindelin
2016-05-20  7:23     ` Pranit Bauva
2016-05-22 19:49       ` Pranit Bauva
2016-05-23 11:09       ` Johannes Schindelin
2016-05-16  7:49   ` Matthieu Moy [this message]
2016-05-16  7:36 ` [PATCH 1/2] bisect--helper: `bisect_log` " Eric Sunshine
2016-05-20  7:28   ` Pranit Bauva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vpqlh3a1lyq.fsf@anie.imag.fr \
    --to=matthieu.moy@grenoble-inp.fr \
    --cc=chriscool@tuxfamily.org \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=pranit.bauva@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.