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

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

Thread Previous | Thread Next
From:
Martijn Lievaart
Date:
December 19, 2021 10:54
Subject:
Re: Pre-RFC: `unknown` versus `undef`
Message ID:
e8e07993-c22c-dc60-9f99-6accb0d938d3@rtij.nl
Op 19-12-2021 om 11:48 schreef Darren Duncan:
>
> Well the other reasonable solution is to treat the pair as "if the 
> expression result is true" and "if the expression result is anything 
> else".  I actually thought of proposing that and then I didn't.
>
> This also means a ternary expression does NOT result in unknown if the 
> test expression is unknown, rather it returns the "else" expression.
>
> However, doing that means these 2 things will behave differently in 
> the presence of unknown where they wouldn't otherwise:
>
>   if ($x) {
>     foo();
>   }
>   else {
>     bar();
>   }
>
>   if ($x) {
>     foo();
>   }
>   if (!$x) {
>     bar();
>   }
>
> Now that may be less surprising and more ideal in the presence of 
> unknown.
>
> What do you think of this alternative?
>

I like it from a conceptual point of view. It feels right. It feels 
correct. But only for new code that is written with this 3VL in mind. 
Otherwise I think it will open a can of bugs in existing code, so that 
probably should still die.


HTH,

M4




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