develooper Front page | perl.perl5.porters | Postings from December 2021

Re: Pre-RFC: `unknown` versus `undef`

Thread Previous | Thread Next
From:
David Nicol
Date:
December 20, 2021 16:30
Subject:
Re: Pre-RFC: `unknown` versus `undef`
Message ID:
CAFwScO8mweiKguj825435bnV6EDqBEV4LEg1P-PL8h=c9DChAQ@mail.gmail.com
I would write that, clearly and efficiently I hope, using a low priority
short-circuiting boolean operator:

     my $total = grep { defined (  $_->value ) and $_->value > $limit  }
@things;

no reason to abuse the ternary op like that.



On Sat, Dec 18, 2021 at 5:09 AM Ovid via perl5-porters <
perl5-porters@perl.org> wrote:

>
> I, for one, am tired of writing code like this:
>
>     my $total = grep { defined $_->value ? $_->value > $limit : 0 }
> @things;
>
> Note: the following is *not* equivalent to the above:
>
>     my $total = grep { ( $_->value // 0 )  > $limit } @things;
>
> I mean, it *looks* correct, but what if the value can be a negative number
> and the limit can be negative? You probably than want this:
>
>     my $total = grep { ( $_->value // ( $limit - 1 ) )  > $limit } @things;
>
> Which arguably might be more confusing than using defined. With 3VL, we
> have this:
>
>     my $total = grep { $_->resolution < $limit } @things;
>
> Worse, I'm tired of tracking down bugs caused by this.
>

-- 
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About