git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Heiko Voigt <hvoigt@hvoigt.net>
To: Karsten Blees <karsten.blees@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Jens Lehmann <jens.lehmann@web.de>,
	Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>
Subject: Re: Re: [PATCH 1/5] hashmap: add enum for hashmap free_entries option
Date: Tue, 17 Jun 2014 21:04:25 +0200	[thread overview]
Message-ID: <20140617190425.GB2982@sandbox-ub> (raw)
In-Reply-To: <539FFCAB.4060908@gmail.com>

On Tue, Jun 17, 2014 at 10:30:35AM +0200, Karsten Blees wrote:
> Am 12.06.2014 21:12, schrieb Junio C Hamano:
> > Karsten Blees <karsten.blees@gmail.com> writes:
> > 
> >> Am 10.06.2014 12:17, schrieb Heiko Voigt:
> >>> The intention of Jonathans critique here[1] was that you do not see what
> >>> this parameter does on the callsite. I.e.:
> >>>
> >>> 	hashmap_free(&map, 1);
> >>>
> >>> compared to
> >>>
> >>> 	hashmap_free(&map, HASHMAP_FREE_ENTRIES);
> >>>
> >>> A boolean basically transfers the same information and would not help
> >>> the reader here.
> >>>
> >>> Cheers Heiko
> >>>
> >>> [1] http://article.gmane.org/gmane.comp.version-control.git/243917
> >>>
> >>
> >> There are languages where you can have e.g. 'hashmap_free(...,
> >> free_entries: true)'. In C, however, you do not see what a
> >> parameter does at the call site. This is a general language
> >> feature, reducing redundancy and keeping it short and concise. IMO
> >> there's no reason to treat boolean parameters differently.
> > 
> > But given that you are writing in C, is any of that relevant?  We do
> > want to keep our call-sites readable and understandable, 
> 
> But in C, readable and understandable are opposite goals.
> 'Understandable' entails long, redundant identifiers, automatically
> decreasing readability. The compiler doesn't care about either, so
> we could just as well keep the C part short and use plain English
> for understandability:
> 
>   /* free maps, except file entries (owned by istate->cache) */
>   hashmap_free(&istate->name_hash, 0);
>   hashmap_free(&istate->dir_hash, 1);
> 
> Note that this not only explains what we're doing, but also why.
> 
> > and 1 or
> > true would not help, unless (1) you are the one who wrote the
> > function and know that 1 means free the entries, or (2) the API is
> > so widely used and everybody knows what 1 means free the entries.
> > 
> 
> or (3) you need to check the function declaration or documentation
> anyway, to understand what the non-boolean parameters do.
> 
> E.g. consider this (from remote.c:1186):
> 
>   dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
> 
> vs.
> 
>   dst_value = resolve_ref_unsafe(matched_src->name, sha1,
>                                  RESOLVE_REF_UNSAFE_FOR_READING,
>                                  &flag);
> 
> That's three lines vs. one, "RESOLVE_REF_UNSAFE_" is completely
> redundant with the function name, "FOR_READING" isn't particularly
> enlightening either, and you still don't know what the other three
> parameters do. IMO this would be much better:
> 
>   /* fully resolve matched symref to resolved ref name and sha1 */
>   dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
> 
> So veterans highly familiar with the code can stick to the C part
> without being distracted by unnecessary line breaks and
> SHOUTED_IDENTIFIERS, while everyone else may find the explanation
> helpful.
> 
> 
> As I said, using enums for hashmap_free isn't a problem on its own.
> However, the accepted solution for booleans in the git code base
> seems to be to use just an int and 0/1.
> 
> For consistency, we could of course change string_list*,
> resolve_ref*, index_file_exists etc. as well.
> 
> ...and in turn 'extern int ignore_case' (because it gets passed to
> index_file_exists)?
> 
> ...and in turn all other boolean config variables?
> 
> I don't think this would be an improvement, though.

If this is such a controversial change for you I will drop this patch in
the next round. I think it would make the callsite more readable without
adding much clutter but I am fine with it either way.

  reply	other threads:[~2014-06-17 19:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05  6:04 [PATCH 0/5] submodule config lookup API Heiko Voigt
2014-06-05  6:06 ` [PATCH 1/5] hashmap: add enum for hashmap free_entries option Heiko Voigt
2014-06-06 17:52   ` Karsten Blees
2014-06-10 10:17     ` Heiko Voigt
2014-06-11  9:12       ` Karsten Blees
2014-06-12 19:12         ` Junio C Hamano
2014-06-17  8:30           ` Karsten Blees
2014-06-17 19:04             ` Heiko Voigt [this message]
2014-06-17 22:19               ` Junio C Hamano
2014-06-05  6:07 ` [PATCH 2/5] implement submodule config cache for lookup of submodule names Heiko Voigt
2014-06-05 17:46   ` W. Trevor King
2014-06-06  5:20     ` Heiko Voigt
2014-06-08  9:04   ` Eric Sunshine
2014-06-10 10:19     ` Heiko Voigt
2014-06-12 21:58   ` Junio C Hamano
2014-06-13 22:37     ` Heiko Voigt
2014-06-05  6:08 ` [PATCH 3/5] extract functions for submodule config set and lookup Heiko Voigt
2014-06-05  6:09 ` [PATCH 4/5] use new config API for worktree configurations of submodules Heiko Voigt
2014-06-05  6:09 ` [PATCH 5/5] do not die on error of parsing fetchrecursesubmodules option Heiko Voigt
2014-06-12 21:59 ` [PATCH 0/5] submodule config lookup API Junio C Hamano
2014-06-13 22:41   ` Heiko Voigt
2014-06-16 17:58     ` Junio C Hamano
2014-06-17 19:00       ` Heiko Voigt
2014-06-12 22:04 ` Junio C Hamano
2014-06-13  7:13   ` Jens Lehmann
2014-06-13 17:50     ` 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

  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=20140617190425.GB2982@sandbox-ub \
    --to=hvoigt@hvoigt.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jens.lehmann@web.de \
    --cc=jrnieder@gmail.com \
    --cc=karsten.blees@gmail.com \
    --cc=peff@peff.net \
    /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).