From: "Florian Gamböck" <mail@floga.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Szeder Gábor" <szeder.dev@gmail.com>
Subject: Re: [RFC PATCH 1/1] completion: load completion file for external subcommand
Date: Mon, 9 Apr 2018 15:36:27 +0200 [thread overview]
Message-ID: <20180409133627.GA25078@arbeitsviech> (raw)
In-Reply-To: <xmqqlgdw67rc.fsf@gitster-ct.c.googlers.com>
On 2018-04-09 18:36, Junio C Hamano wrote:
> Florian Gamböck <mail@floga.de> writes:
>
> > Good point. I could go even further and ditch the if-construct:
> >
> > ! declare -f $completion_func && declare -f __load_completion &&
> > __load_completion "git-$command"
>
> I personally find that a lot harder to read than if/then/fi.
Then I mis-understood you the first time. It sounded a bit as if you
wanted to avoid if-fi. After all, the rest of this code block also uses
quite long &&-chains.
Then we are back at the first question:
> > local completion_func="_git_${command//-/_}"
> > + if ! declare -f $completion_func >/dev/null 2>/dev/null; then
> > + declare -f __load_completion >/dev/null 2>/dev/null &&
> > + __load_completion "git-$command"
>
> wouldn't the above be easier to read if it were
>
> if ! declare ... $completion_func ... && declare -f __load_completion
> then
> __load_completion "git-$command"
> fi
>
> or is there a reason why it is better to &&-chain the check for
> __load_completion with its use?
As for readability, I would prefer my first approach then with the
following reasoning: Checking the existence of a function and actually
calling it can be seen as a unit. Either the function does not exist or
you call it. You could even create a function like "call_if_exists",
that does exactly this. Either way, at the end of the line you are
smarter than before. As for the if-statement, this describes the reason
why you even want to load an external file. If the function in question
($completion_func) already exists, we do not want to load it again. If
you chain the statement with the existence check of __load_completion,
you make it look like those two functions are somehow related, which is
not the case.
To put it in words: "If $completion_func does not already exist, then
load another file (if you know how to do that)." versus "If
$completion_func does not yet exist and you know how to load another
file, then load another file." The difference is subtle, but I think the
first sentence better describes the intention.
Does my reasoning make sense? I mean, the result will be exactly the
same, we are clearly only talking about readability here.
next prev parent reply other threads:[~2018-04-09 13:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-08 18:26 [RFC PATCH 0/1] completion: Dynamic completion loading Florian Gamböck
2018-04-08 18:26 ` [RFC PATCH 1/1] completion: Load completion file for external subcommand Florian Gamböck
2018-04-08 18:29 ` Florian Gamböck
2018-04-09 18:26 ` Stefan Beller
2018-04-09 19:49 ` Florian Gamböck
2018-04-19 14:12 ` SZEDER Gábor
2018-04-08 18:26 ` [RFC PATCH 1/1] completion: load " Florian Gamböck
2018-04-08 22:59 ` Junio C Hamano
2018-04-09 7:29 ` Florian Gamböck
2018-04-09 9:36 ` Junio C Hamano
2018-04-09 13:36 ` Florian Gamböck [this message]
2018-04-09 22:06 ` Junio C Hamano
2018-04-10 9:37 ` Florian Gamböck
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=20180409133627.GA25078@arbeitsviech \
--to=mail@floga.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=szeder.dev@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.