3 ms·
Most are not quircks of implicit type conversion, they happen because of the "no errors, at any cost" phylosophy of the language. 1 + "five" is an error in PHP
by marcosdumay 3y ago
Most are not quircks of implicit type conversion, they happen because of the "no errors, at any cost" phylosophy of the language.
1 + "five" is an error in PHP, not some random correct-looking value.
- Groxx 3y agoIn recent PHPs, yes, as they've gotten a lot more strict. On older ones though, it's not an error: https://onlinephp.io?s=s7EvyCjg5UpNzshXMFTQVlBKyyxLVbIGAA%2C%2C&v=5.6.40 https://onlinephp.io?s=s7EvyCjg5UpNzshXMFTQVlBKyyxLVbIGAA%2C... Even in the previous major version (7) it's only a warning. I agree that philosophy is likely the main cause of decisions like this, but JS is hardly unique in having it.
- chrisjj 3y ago> "no errors, at any cost" Meaning of course "no errors reported, at any cost". Programming language language has redefined "error" - to substantial cost to programmers.
- bennyelv 3y agoWhen your system gets to a certain size, this is absolutely fatal. Please halt and throw a massive exception, shrugging and carrying on makes bugs impossible to track down and the whole system unpredictable. It’s a philosophy that might be acceptable for a simple-ish frontend, but when if you try and build something significant it’s just awful. Source: I inherited responsibility for a > 5m LOC system written in JavaScript. The problems aren’t all JavaScript’s fault, but it does play a major part in it.
- chrisjj 3y ago> Please halt and throw a massive exception +1 A case I'm struggling with recently is Fastmail mail search. Given a valid query which it cannot handle, rather than show an error report, it does its "best" and delivers a false result. With potentially great cost to the unwitting user. Is there even a warning on the doc page?? No.
- paulddraper 3y ago> 1 + "five" Forget JavaScript, that's not even an error in Java.
- marcosdumay 3y agoYes, Java has this one strong inconsistency on its type system. The interesting thing is that the addition operator has a not completely predictable behavior exactly because the language designers insisted that custom operators reduce the language predictability. But anyway, it's much less bad in Java because you can force it to err by declaring what type of thing you want it to return.
- white_dragon88 3y ago[dead]