Re: [PATCH] gitweb: merge boolean feature subroutines
- From
- Matt Kraai <kraai@ftbfs.org>
- Date
- Jan 4, 2009, 15:58 UTC
- Message-ID
- <20090104155858.GC4205@ftbfs.org>
- In-Reply-To
- <9b18b3110901040341n5ff5fa09s878228131d11d2a6@mail.gmail.com>
On Sun, Jan 04, 2009 at 12:41:14PM +0100, demerphq wrote:
Show 25 quoted lines
> 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.I agree that what you suggest is better than the alternatives you present. Unfortunately, none of them match the current behavior. Here's the current code:
if ($val eq 'true') {
return 1;
} elsif ($val eq 'false') {
return 0;
}return $_[0];
Is there a way to use the form you suggest while falling back to the default if $val isn't set to 'true' or 'false'?
-- Matt http://ftbfs.org/