git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Michael Lohmann <mi.al.lohmann@gmail.com>,
	 git@vger.kernel.org, phillip.wood123@gmail.com,
	 phillip.wood@dunelm.org.uk, wanja.hentze@bevuta.com
Subject: Re: [PATCH v3] builtin/revert.c: refactor using an enum for cmd-action
Date: Fri, 12 Jan 2024 10:13:03 -0800	[thread overview]
Message-ID: <xmqqil3ybets.fsf@gitster.g> (raw)
In-Reply-To: <20240112072404.GF618729@coredump.intra.peff.net> (Jeff King's message of "Fri, 12 Jan 2024 02:24:04 -0500")

Jeff King <peff@peff.net> writes:

> But your way of seeing it also makes sense to me. I think I just find
> the "START" name jarring because we do not use that word elsewhere to
> describe the action.

Thanks.  I forgot to say that I share the same feeling, both about
"NONE could mean no-op" (but then seriously why would anybody sane
want that?) and "START is not how we spell these things".  I can see
how DEFAULT could make sense, but if somebody picked DEFAULT between
two sensible choices NONE and DEFAULT here, especially if they claim
that they started this enum to mimick what is done in another place,
and after they were told that the other place they are imitating
follows the convention of using NONE for "nothing specified, so use
default", I would have to say that they are trying to be different
for the sake of being different, which is not a good sign.  I'd want
our contributors to be original where being original matters more.

>> +{
>> +	switch (cmd) {
>> +	case ACTION_CONTINUE: return "--continue";
>> +	case ACTION_SKIP: return "--skip";
>> +	case ACTION_ABORT: return "--abort";
>> +	case ACTION_QUIT: return "--quit";
>> +	case ACTION_START: BUG("no commandline flag for ACTION_START");
>> +	}
>> +}
>
> I find this perfectly readable, and is likely the way I'd write it in a
> personal project. But in this project I find we tend to stick to more
> conventional formatting, like:
>
>   switch (cmd) {
>   case ACTION_CONTINUE:
> 	return "--continue";
>   case ACTION_SKIP:
> 	return "--skip";
>   ...and so on...

Same.  I try to do the latter while working on this project, but I
do admit I use the former in small one-page tools I write outside
the context of this project.

>> +	if (cmd != ACTION_START)
>
> Likewise here I'd probably leave this as "if (cmd)".

I 100% agree with the suggestion to explicitly define something to
be 0 when we are going to use it for its Boolean value.  So an
alternative would be to treat all ACTION_* enum values the same, and
not define the first one explicitly to 0.  

Especially in the context of a patch that wants to turn if/elseif
cascades to switch, I would suspect that the latter, as switch/case
does not special case the falsehood among other possible values of
integer type, might be easier to maintain in the longer term.

Thanks.


  reply	other threads:[~2024-01-12 18:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11  8:04 [PATCH] builtin/revert.c: refactor using an enum for cmd-action Michael Lohmann
2024-01-11 16:57 ` Phillip Wood
2024-01-11 17:47   ` [PATCH v2] " Michael Lohmann
2024-01-11 19:50     ` Junio C Hamano
2024-01-11 20:06       ` [PATCH v3] " Michael Lohmann
2024-01-11 21:47         ` Junio C Hamano
2024-01-12  0:40         ` Junio C Hamano
2024-01-12  7:24         ` Jeff King
2024-01-12 18:13           ` Junio C Hamano [this message]
2024-01-12 19:33             ` Michael Lohmann
2024-01-11 19:37   ` [PATCH] " Junio C Hamano

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=xmqqil3ybets.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mi.al.lohmann@gmail.com \
    --cc=peff@peff.net \
    --cc=phillip.wood123@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=wanja.hentze@bevuta.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).