3 ms·
It's the kind of thing you get with weak typing. Perl does better here by requiring "eq" for strings, so there's less chance for such an issue to happen. But y
by dale_glass 4y ago
It's the kind of thing you get with weak typing.
Perl does better here by requiring "eq" for strings, so there's less chance for such an issue to happen. But you have the "zero but true" fun quirk -- "0e0" evaluates to 0 numerically, but 1 logically because it's not an empty string.
- eknkc 4y agoYeah but there are levels of weak typing. JS does not do this as both operands are strings, it compares them as strings. That makes tons of more sense compared to this. Not that JS is the most sane language out there but PHP tends to make it a lot easier to shoot yourself.
- tuyiown 4y agoThe casting occurs for both operands that have same type, in narrower type space, with non trivial rules, behind your back, is really acid level of a surprise. The kind that would make the removal of the "==" operator reasonable.
- VHRanger 4y agoPython does weak typing and doesn't have 1% of the unexpected nonsense PHP has.
- mkl 4y agoYou're probably thinking of dynamic typing, which Python has, but Python's typing is strong, not weak, so e.g. '1' == 1 returns False.
- zarzavat 4y agoPython has strong typing, but it does use duck typing. Weak typing is when a language inserts implicit coercions in unexpected places, such as 42 == “42”. It’s not a precisely defined term. Another example is in C where pointers and values may be mixed and matched, although less so nowadays.
- giantrobot 4y agoPython has dynamic but strong typing. There's no hidden type coercion. A dev might run into behavior they don't expect but the behavior is documented and regular.
- vhcr 4y agoPython is strongly typed though.