git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jakub Narebski <jnareb@gmail.com>
Cc: Eric Wong <normalperson@yhbt.net>,
	Cord Seele <cowose@googlemail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	git@vger.kernel.org, Cord Seele <cowose@gmail.com>
Subject: Re: [PATCH/RFC 3/2 v3] Refactor Git::config_*
Date: Tue, 18 Oct 2011 16:25:08 -0700	[thread overview]
Message-ID: <7vmxcxg9wr.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <201110190009.40470.jnareb@gmail.com> (Jakub Narebski's message of "Wed, 19 Oct 2011 00:09:39 +0200")

Jakub Narebski <jnareb@gmail.com> writes:

>> Well, this breaks t9001 and I ended up spending an hour and half figuring
>> out why. Admittedly, I was doing something else on the side, so it is not
>> like the whole 90 minutes is the billable hour for reviewing this patch,
>> but as far as the Git project is concerned, I didn't have any other branch
>> checked out in my working tree, so that whole time was what ended up
>> costing.
>
> I'm sorry about that.

No need to be sorry. After all you just re-sent a throw-away patch with
minor tweaks, but unfortunately a tricky Perl script sometimes needs line
by line inspection with fine toothed comb to avoid regression.

>> The real problem was here.
>> ...
>> > -		my $val = command_oneline(@cmd);
>> > -		return undef unless defined $val;
>> > -		return $val eq 'true';
>> > ...
>> > -	};
>> > +	my $val = scalar _config_common($self, $var, {'kind' => '--bool'});
>> > +	return (defined $val && $val eq 'true');
>> >  }
>> 
>> Can you spot the difference?
>
> Damn.

For people following from the sideline, the difference that bit us was
that

    return $val eq 'true';

yields "" (not undef) for false, but some callers care the distinction
between undef kind of false and other kinds of false. It is not really the
fault of the language per-se, but still... 

>> This is the reason why I do not particularly like a rewrite for the sake
>> of rewriting.
>
> The goal was to reduce code duplication to _avoid_ errors.

That is exactly why I said I do not like a rewrite for such purpose.

Once the end result of smaller code is done correctly, it would help
avoiding future errors, but people tend to think unconsciously that the
change to reduce code duplication is much safer than adding new code.
Upon receiving such a patch, without knowing that it was not done with
enough attention to detail with fine toothed comb, it is me who ends up
spending nontrivial amount of time fixing the breakage. These "clean-ups"
are not cheap.

> What I have noticed is that there is slight difference between original
> Git::config_path and the one after refactoring.  In the version before
> this patch the error catching part of config_path() looks like this:
> ...
>                         return undef;
> ...
> while after this patch (and in config()) it looks like this:
> ...
>                         return;
> ...

> I am not sure which one is right, but I suspect the latter.

This is Perl---"return;" returns undef, so there is no right or wrong.

Having said that, I tend to prefer being explicit so that people not so
familiar with the language do not have to waste time wondering about such
differences. Especially where it matters, like this case where some
callers may care about different kinds of falsehood.

That is another reason I tend to hate the kind of "this makes it more
Perl-ish" changes, as they tend to force readers to spend extra brain
cells to see what is going on. I'd rather spell things more explicit,
especially when the distinction matters.

I've already pushed out the fixed one as 6942a3d (libperl-git: refactor
Git::config_*, 2011-10-18), with this bit:

    - ...
    -               my $val = command_oneline(@cmd);
    -               return undef unless defined $val;
    +       # Do not rewrite this as return (defined $val && $val eq 'true')
    +       # as some callers do care what kind of falsehood they receive.
    +       if (!defined $val) {
    +               return undef;
    +       } else {
                    return $val eq 'true';
      ...

  reply	other threads:[~2011-10-18 23:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-28 13:13 [PATCH] git-send-email.perl: expand filename of aliasesfile Cord Seele
2011-09-28 13:42 ` Matthieu Moy
2011-09-28 14:40   ` Cord Seele
2011-09-28 14:47     ` Matthieu Moy
2011-09-30 10:52       ` [PATCH v2] git-send-email: allow filename expansion Cord Seele
2011-09-30 10:52         ` [PATCH 1/2] Add Git::config_path() Cord Seele
2011-10-07 20:32           ` Jakub Narebski
2011-10-07 21:35             ` Junio C Hamano
2011-10-07 21:44               ` Jakub Narebski
2011-10-07 22:26                 ` Junio C Hamano
2011-09-30 10:52         ` [PATCH 2/2] use new Git::config_path() for aliasesfile Cord Seele
2011-09-30 19:55           ` Junio C Hamano
2011-09-30 21:16             ` Cord Seele
2011-09-30 22:00             ` Jakub Narebski
2011-09-30 22:18               ` Junio C Hamano
2011-10-07 21:17                 ` [PATCH/RFC 3/2] Refactor Git::config_* Jakub Narebski
2011-10-17 20:50                   ` Junio C Hamano
2011-10-17 21:47                     ` Jakub Narebski
2011-10-17 23:25                       ` Junio C Hamano
2011-10-18  9:47                       ` [PATCH/RFC 3/2 (fixed)] " Jakub Narebski
2011-10-18 19:52                         ` Junio C Hamano
2011-10-18 22:09                           ` [PATCH/RFC 3/2 v3] " Jakub Narebski
2011-10-18 23:25                             ` Junio C Hamano [this message]
2011-10-19  0:19                               ` Jakub Narebski

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=7vmxcxg9wr.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=cowose@gmail.com \
    --cc=cowose@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    --cc=normalperson@yhbt.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.
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).