5 ms·
In a language which doesn't understand that "false" isn't true? I would be entirely unsurprised to discover it's secretly calling a browser vendor web API to se
by tialaramex 1y ago
In a language which doesn't understand that "false" isn't true? I would be entirely unsurprised to discover it's secretly calling a browser vendor web API to search for similarly named dates, or that it's now AI powered and might decide "Last Christmas" means the release date (December 3 1984) of the single not like, Christmas Day in 2024...
I think after the 1970s "Worse is better" languages vanish from the Earth the last shadow of that thinking left might be Javascript, hopefully by then humans aren't writing it but of course for "compatibility" it'll still be implemented by web browsers.
- nailer 1y agoWhat do you mean? false isn’t true in JavaScript.
- Filligree 1y ago“false”, not false. So there’s odd type coercion, but the problem is that it can happen without you asking for it. Python does the same thing. I don’t like it there either, but at least it’s more consistent about it.
- astura 1y agoThe string with the value of "false" evaluates to true. In other words If ("false") { /* You will be here */ }
- wiseowise 1y agoWhy wouldn’t “false” be true? It’s a non-empty string.
- ascar 1y agoyea that's an odd example to pick. expecting type conversion to add meaning to strings is a programmer problem not a language problem. really comes down to developers not thinking about types and their meaning anymore. there are plenty of javascript examples that are actually weird though, especiall when javascript DOES apply meaning to strings, e.g. when attempting implicit integer parsing.
- 010101010101 1y agoIt’s the _existence_ of an implicit conversion from string to boolean that the parent is pointing out as a problem, not how it’s implemented. But that’s Jãvascript bb
- echoangle 1y agoMaybe I’m missing the example but can you not check the truthiness of strings in basically any high level language? At least python does it the same way and it’s very useful.
- 010101010101 1y agoneither Java nor .Net have implicit string to boolean conversions, the only way to asses the truthiness of a string is an explicit conversion - there’s no “if(someStringVariable)” - that’s just a type error at compile time.
- tialaramex 1y agoFor the same reason dogs aren't the square root of two and justice isn't golf? They're not the same kind of thing at all, if you insist that we should be able to compare them then they're not equal, and since programmers are human and make mistakes probably comparing them is itself a mistake.
- bapak 1y agoAre you crazy? Which language does? I can only think of markup languages that do. Should "0" also === 0? How about "{}" === {}? When does it stop?