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

Re: Pre-RFC: Real "boolean" SV type

Thread Previous | Thread Next
Tomasz Konojacki
August 4, 2021 23:04
Re: Pre-RFC: Real "boolean" SV type
Message ID:
On Wed, 4 Aug 2021 15:30:35 -0700
Aaron Priven <> wrote:

> I don’t have a problem with the proposal per se, but it’s hard for me to believe that inferring what type a value should be from its initial assignment is going to be reliable.
> Surely there’s a lot of extant code like
>   if ($condition) {
>      $flag = $x eq $y;
>   } else {
>      do_something();
>      $flag = 1;
>   }
>   $count+= $flag;
> Is $flag a boolean or an integer? 
> I can appreciate the desire to have serializers work on data without having to pass type information separately, but it seems really unlikely to me that it’s possible to be consistent without being explicit.

if ($condition) {
    $flag = $x eq $y; # boolean
} else {
    $flag = 1; # not a boolean, replace it with !!1 or true
$count+= $flag; # not a boolean

Anyway, yes, it won't magically fix all existing code. But it will give
the users *a way* to create variables that will reliably serialize as
booleans. Of course, often you will have to normalize your values just
before passing them to a serializer, but it's still a huge improvement.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About