From: Heba Waly <heba.waly@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Heba Waly via GitGitGadget <gitgitgadget@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH v5 2/3] advice: revamp advise API
Date: Wed, 26 Feb 2020 13:37:36 +1300 [thread overview]
Message-ID: <CACg5j25EdX2fPHpAq3TEhaJPiQg4dA52soOyCMm17wg_O-c4Ng@mail.gmail.com> (raw)
In-Reply-To: <xmqqy2sql405.fsf@gitster-ct.c.googlers.com>
On Wed, Feb 26, 2020 at 11:02 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Heba Waly <heba.waly@gmail.com> writes:
>
> > I wasn't very happy about having to keep the list of config keys in
> > memory, but that was a good enough solution for now.
>
> If you force your programmers to specify the advice_type as a small
> integer, and the setting is stored in the config as string keys,
> somebody MUST have a table to convert from one to the other. So I
> am not sure if it is even sensible to feel unhappy about having to
> have a list in the first place. Are we looking for some kind of
> miracles ;-)?
>
The reason I had to add the list of keys wasn't the enums, but because
it's needed by list_config_advices() which returns all the advice
config variables names. This is used when the user runs `git help
--config`.
And as a result, I added the enum to utilize it in accessing the list
and avoid hard coded strings in functions calls.
> On the other hand, it does bother my sense of aesthetics a lot it
> our code forces our programmers to give a small integer to us, only
> so that we convert that integer to a string and use the string to
> look up a value in a hashtable, every time the program wants a
> lookup. Performance-wise, that's not a huge downside. It just rubs
> my sense of code hygiene the wrong way.
>
> Especially when the primary way for our programmers to specify which
> advice they are talking about is by passing an integer, and if we
> need to have a table indexed by that integer in the program anyway.
>
> We could instead do something like:
>
> /* advice.h */
> #ifndef _ADVICE_H_
> #define _ADVICE_H_ 1
> extern const char ADVICE_ADD_EMBEDDED_REPO[];
> extern const char ADVICE_AM_WORK_DIR[];
> ...
> #endif
>
> /* advice.c */
> const char ADVICE_ADD_EMBEDDED_REPO[] = "advice.addEmbeddedRepo";
> const char ADVICE_ADD_AM_WORK_DIR[] = "advice.amWorkDir";
> ...
>
> and the callers can still do
>
> advise_if_enabled(ADVICE_NESTED_TAG,
> _(message_advice_nested_tag), tag, object_ref);
>
> with the benefit of compiler catching a silly typo, without having
> to have any "enum-to-string" table while letting the config API
> layer do any caching transparently. As these calls will never be
> placed in a performance critical codepath, that might be more
> appropriate.
>
I'm not against this approach as well, but as I mentioned above, we
need a list of keys to be returned by list_config_advices(), that's
why defining the constant strings will not be sufficient in our case.
Thanks,
Heba
next prev parent reply other threads:[~2020-02-26 0:37 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 5:04 [PATCH] advice: refactor advise API Heba Waly via GitGitGadget
2020-02-10 14:38 ` Derrick Stolee
2020-02-10 19:30 ` Junio C Hamano
2020-02-10 19:42 ` Taylor Blau
2020-02-10 22:29 ` Emily Shaffer
2020-02-11 0:08 ` Heba Waly
2020-02-12 20:57 ` Taylor Blau
2020-02-10 23:56 ` Heba Waly
2020-02-11 2:39 ` Derrick Stolee
2020-02-10 20:37 ` Jeff King
2020-02-10 22:55 ` Emily Shaffer
2020-02-11 2:35 ` Heba Waly
2020-02-11 19:49 ` Jeff King
2020-02-11 19:51 ` Jeff King
2020-02-11 2:20 ` Heba Waly
2020-02-10 22:46 ` Junio C Hamano
2020-02-11 2:01 ` Heba Waly
2020-02-11 6:08 ` Junio C Hamano
2020-02-16 21:39 ` [PATCH v2 0/2] [RFC][Outreachy] " Heba Waly via GitGitGadget
2020-02-16 21:39 ` [PATCH v2 1/2] " Heba Waly via GitGitGadget
2020-02-17 3:28 ` Junio C Hamano
2020-02-17 10:03 ` Heba Waly
2020-02-19 9:59 ` Heba Waly
2020-02-16 21:39 ` [PATCH v2 2/2] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-02-17 0:09 ` [PATCH v2 0/2] [RFC][Outreachy] advice: refactor advise API Junio C Hamano
2020-02-19 20:33 ` [PATCH v3 0/2] [Outreachy] advice: revamp " Heba Waly via GitGitGadget
2020-02-19 20:34 ` [PATCH v3 1/2] " Heba Waly via GitGitGadget
2020-02-20 1:37 ` Emily Shaffer
2020-02-21 0:31 ` Heba Waly
2020-02-19 20:34 ` [PATCH v3 2/2] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-02-20 1:42 ` Emily Shaffer
2020-02-21 0:34 ` Heba Waly
2020-02-24 15:13 ` [PATCH v4 0/3] [Outreachy] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-24 15:13 ` [PATCH v4 1/3] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-02-24 22:04 ` Emily Shaffer
2020-02-24 15:13 ` [PATCH v4 2/3] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-24 22:05 ` Junio C Hamano
2020-02-24 22:11 ` Eric Sunshine
2020-02-24 23:51 ` Heba Waly
2020-02-24 23:49 ` Heba Waly
2020-02-24 23:45 ` Emily Shaffer
2020-02-24 15:13 ` [PATCH v4 3/3] tag: use new advice API to check visibility Heba Waly via GitGitGadget
2020-02-24 22:07 ` Junio C Hamano
2020-02-24 23:46 ` Emily Shaffer
2020-02-25 10:55 ` [PATCH v5 0/3] [Outreachy] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-25 10:55 ` [PATCH v5 1/3] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-02-25 10:55 ` [PATCH v5 2/3] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-25 17:40 ` Junio C Hamano
2020-02-25 19:56 ` Emily Shaffer
2020-02-25 20:09 ` Junio C Hamano
2020-02-25 20:35 ` Junio C Hamano
2020-02-25 21:19 ` Heba Waly
2020-02-25 22:02 ` Junio C Hamano
2020-02-26 0:37 ` Heba Waly [this message]
2020-02-26 3:03 ` Junio C Hamano
2020-02-26 20:28 ` Heba Waly
2020-02-26 20:44 ` Junio C Hamano
2020-02-26 21:48 ` Jonathan Tan
2020-02-25 10:55 ` [PATCH v5 3/3] tag: use new advice API to check visibility Heba Waly via GitGitGadget
2020-02-25 17:48 ` Junio C Hamano
2020-02-27 4:35 ` [PATCH v6 0/4] [Outreachy] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-27 4:35 ` [PATCH v6 1/4] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-02-27 4:35 ` [PATCH v6 2/4] advice: change "setupStreamFailure" to "setUpstreamFailure" Heba Waly via GitGitGadget
2020-02-27 17:38 ` Junio C Hamano
2020-02-27 4:35 ` [PATCH v6 3/4] advice: revamp advise API Heba Waly via GitGitGadget
2020-02-27 20:49 ` Junio C Hamano
2020-02-29 0:58 ` Heba Waly
2020-02-27 4:35 ` [PATCH v6 4/4] tag: use new advice API to check visibility Heba Waly via GitGitGadget
2020-03-02 20:01 ` [PATCH v7 0/4] [Outreachy] advice: revamp advise API Heba Waly via GitGitGadget
2020-03-02 20:01 ` [PATCH v7 1/4] advice: extract vadvise() from advise() Heba Waly via GitGitGadget
2020-03-02 20:01 ` [PATCH v7 2/4] advice: change "setupStreamFailure" to "setUpstreamFailure" Heba Waly via GitGitGadget
2020-03-02 20:01 ` [PATCH v7 3/4] advice: revamp advise API Heba Waly via GitGitGadget
2020-03-02 21:03 ` Junio C Hamano
2020-03-03 14:15 ` Junio C Hamano
2020-03-04 3:22 ` Heba Waly
2020-03-02 20:02 ` [PATCH v7 4/4] tag: use new advice API to check visibility Heba Waly via GitGitGadget
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACg5j25EdX2fPHpAq3TEhaJPiQg4dA52soOyCMm17wg_O-c4Ng@mail.gmail.com \
--to=heba.waly@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).