On Sun, 19 Dec 2021 13:13:28 -0800 Darren Duncan <darren@darrenduncan.net> wrote: > On 2021-12-19 4:13 a.m., Ovid via perl5-porters wrote: > > In Perl, $var might be undef and be evaluated as less than three. > > However, $var might be the string "Hello, World". $var might also > > be a reference to a hash, we get absolutely no warning, and we hit > > our else block with an assumption that is probably true ($var <= > > 3), but not in this particular case. We _should_ be verifying what > > kind of data that $var holds, but usually we don't. > > > > Thus, in a dynamic language like Perl, barring validating our data > > up front, the else block very often makes no guarantees about what > > kinds of data that we have. > > It seems to me that the real problem here is more that we're seeing a > consequence of Perl's weak typing, where values of one type are > automatically cast as values of another type when we try to treat > them as the latter. The "undef" problem is a key example of this but > there is also the other examples you cite. > > I feel that a much better solution to the real problem is to support > stronger typing in Perl, make it possible for values to NOT > automatically convert to other types, and instead raise an error. Such as my "no stringification" idea, and also a similar one for numbers. Yes that's on my list to think about properly. Maybe sometime in the 5.37 series... -- Paul "LeoNerd" Evans leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/Thread Previous | Thread Next