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

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

Thread Previous | Thread Next
Darren Duncan
August 5, 2021 06:49
Re: Pre-RFC: Real "boolean" SV type
Message ID:
On 2021-08-04 11:28 p.m., Ovid via perl5-porters wrote:
> One question, how would it handle this annoyance?
>     #!/usr/bin/env perl
>     use strict;
>     use warnings;
>     my @list    = map { rand(50) } 1 .. 10;
>     my $matches = 0;
>     for (@list) {
>        $matches += $_ > 25; # ???
>     }
>     print "Matches = $matches\n";
> Yes, that's an abuse, but it's the kind of crud we see in the wild (and it 
> doesn't throw any warnings);

As a further response,

Something else we can do, and we can actually do this independently of the 
boolean type stuff, is add new warning types that trigger whenever an implicit 
type cast happens, such as when using a string as a number or vice versa.

So though such casting behavior is well defined it can still warn if we consider 
that a bad coding design.

In that case though we would also need to have canonical explicit conversion 
syntax/routines/operators such that one can replace the then-warning code, which 
would include idioms like "0+$str", with something that wouldn't warn because 
the conversion is explicit.

-- Darren Duncan

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