git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC 3/2 v3] Refactor Git::config_*

From
Jakub Narebski <jnareb@gmail.com>
Date
Oct 19, 2011, 00:19 UTC
Message-ID
<201110190219.38331.jnareb@gmail.com>
In-Reply-To
<7vmxcxg9wr.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 25 quoted lines
> Jakub Narebski <jnareb@gmail.com> writes:
> 
>>> 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... 
And Git::config* family of commands return 'undef' if key was not found.
So Git::config_bool() can return true, false or undef, and the last part
is important. 
 
Show 14 quoted lines
>> 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.
Actually this is not true: "return;" returns undef in scalar context,
and empty list in list context.  This means that result always evaluates
to false...
 
Show 9 quoted lines
> 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.
...and that is why "return;" is more Perl-ish, and usually safer.
There might be exceptions where we want to return one-element list
containing single undef element in list context, but I guess they
are exceedingly rare.
 
Show 13 quoted lines
> 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';
>       ...
I like mine better... ;-))))
-- 
Jakub Narebski
Poland
Previous: Junio C Hamano
Message 24 of 24 in “git-send-email.perl: expand filename of aliasesfile”
  1. git-send-email.perl: expand filename of aliasesfileCord Seele, Sep 28, 2011
  2. Matthieu MoySep 28, 2011
  3. Cord SeeleSep 28, 2011
  4. Matthieu MoySep 28, 2011
  5. git-send-email: allow filename expansionCord Seele, Sep 30, 2011
  6. 1/2 Add Git::config_path()Cord Seele, Sep 30, 2011
  7. Jakub NarebskiOct 7, 2011
  8. Junio C HamanoOct 7, 2011
  9. Jakub NarebskiOct 7, 2011
  10. Junio C HamanoOct 7, 2011
  11. 2/2 use new Git::config_path() for aliasesfileCord Seele, Sep 30, 2011
  12. Junio C HamanoSep 30, 2011
  13. Cord SeeleSep 30, 2011
  14. Jakub NarebskiSep 30, 2011
  15. Junio C HamanoSep 30, 2011
  16. 3/2 Refactor Git::config_*Jakub Narebski, Oct 7, 2011
  17. Junio C HamanoOct 17, 2011
  18. Jakub NarebskiOct 17, 2011
  19. Junio C HamanoOct 17, 2011
  20. 3/2 Refactor Git::config_*Jakub Narebski, Oct 18, 2011
  21. Junio C HamanoOct 18, 2011
  22. 3/2 Refactor Git::config_*Jakub Narebski, Oct 18, 2011
  23. Junio C HamanoOct 18, 2011
  24. Jakub NarebskiOct 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.