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

Re: [PATCH] gitweb: merge boolean feature subroutines

From
Ddemerphq <demerphq@gmail.com>
Date
Jan 4, 2009, 11:41 UTC
Message-ID
<9b18b3110901040341n5ff5fa09s878228131d11d2a6@mail.gmail.com>
In-Reply-To
<7vvdsv3af6.fsf@gitster.siamese.dyndns.org>
2009/1/4 Junio C Hamano <gitster@pobox.com>:
Show 23 quoted lines
> demerphq <demerphq@gmail.com> writes:
>
>> 2009/1/3 Matt Kraai <kraai@ftbfs.org>:
>> [...]
>>> -sub feature_blame {
>>> -       my ($val) = git_get_project_config('blame', '--bool');
>>> +sub feature_bool {
>>> +       my $key = shift;
>>> +       my ($val) = git_get_project_config($key, '--bool');
>>>
>>>        if ($val eq 'true') {
>>>                return 1;
>>
>> Maybe that should be:
>>
>>            return ($val eq 'true');
>>
>> as It is not a good idea to use 0 as a replacement for perls false, as
>> the two have different behaviour.
>
> I'd rather want to keep our scripts free of deep Perl magic.  Even if
> there are SVs that are interpreted as false other than 0, that does not
> necessarily mean you have to fear that 0 can sometimes evaluate to true.

No, thats not the point. The point is that why should the code do more work to return a value that a perl programmer might find unexpected. Especially when the function has the word "bool" in it. Its like writing a function whose name says "int" that returns a double. If the routine was not called "bool" then it wouldnt matter at all.

> As long as you refrain from doing something crazy like "0 but true",
> people who are not (and/or are not inclined to become) familiar with the
> gory innards of Perl can rely on 0 being false and 1 being true when
> calling feature_something subs, no?

Why execute more opcodes, and return a slightly surprising false, when you dont have to?

Is it really deep perl magic to do:
  return $val eq 'true';
instead of
  return $val eq 'true' ? 1 : 0;
or the actual use:
   if ($val eq 'true') {
      return 1
   } else {
      return 0
   }

Isn't the former superior just on pure minimalism metrics? Theres less code to understand, less code to go wrong, and as a bonus it returns a true boolean. Isn't that just a win-win-win? I mean most perl programmers I know would instantly convert the latter two to the first just on the grounds that the first version is the clearest expression of the desired intent.

Anyway, leave it or not, its a minor nit.

cheers, Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"
Previous: Junio C HamanoNext: Matt Kraai
Message 9 of 12 in “gitweb: merge boolean feature subroutines”
  1. gitweb: merge boolean feature subroutinesMatt Kraai, Jan 3, 2009
  2. gitweb: pass the key to the feature subroutinesMatt Kraai, Jan 3, 2009
  3. demerphqJan 3, 2009
  4. Matt KraaiJan 3, 2009
  5. demerphqJan 3, 2009
  6. Matt KraaiJan 3, 2009
  7. demerphqJan 3, 2009
  8. Junio C HamanoJan 4, 2009
  9. demerphqJan 4, 2009
  10. Matt KraaiJan 4, 2009
  11. Jakub NarebskiJan 4, 2009
  12. Junio C HamanoJan 4, 2009

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.