5 ms·
Ugh. Many parts of javascript are nice but things like this (''==0?) make me wish for a browser-supported language that was clean.
by PeterisP 13y ago
Ugh. Many parts of javascript are nice but things like this (''==0?) make me wish for a browser-supported language that was clean.
- jonpaul 13y agoYea, or you could use "===".
- jkrems 13y agoSince comparing strings and numbers generally doesn't make a lot of sense, you could just consider it a case of "undefined behavior". As many other people will write: There's only one case I can think of where the unsafe-equals operator is reasonable and that's `a == null` to check for null/undefined.
- jonpaul 13y agoYep. Along with `== null`. I also only use "==" with `typeof` since `typeof` always returns a string.
- marcosdumay 13y agoMost languages call those situations by the name "runtime error", that is, when it is even possible that they happen at runtime. Now, I understand that javascript runs in a completely different kind of environment, and it does have the liberty of making things differently, up to a certain point. But making '' == 0 true may be a bit too far.. And making [1] == 1 true is clearly too far.
- TheZenPsycho 13y agolike what? php? visual basic? c? java? define "clean" and name one language in the history of computing that actually fits that definition.
- Dylan16807 13y agoLua.
- TheZenPsycho 13y agoAs much as I like lua, it doesn't really meet the challenge I set forth. For one, you forgot to define "clean". For another, if you put lua in the browser instead of javascript, how long do you think it will be before lua starts growing horrible warts as well?
- rdtsc 13y agoPython, Ruby, Dart just to name a few from the top of my head. EDIT: removed Java, Rust and Go
- TheZenPsycho 13y agoYou forgot to define "clean". Also, java is in your list. Java had its chance. it failed. did you forget that? So has Dart. how's dart doing? Rust as a web scripting language doesn't even make sense.
- PeterisP 13y agoI'll define "clean" as a language that has been intentionally designed with a goal to make language features interact in intuitive ways - i.e., that if something looks like X, then it also acts like X; and also behave safely, i.e., undefined behavior is minimized or eliminated if possible. 'Evolved' languages tend to be less clean than 'designed' ones, and also any language accumulates cruft with time if features are added carelessly - for example, C++ can never be 'clean' even if C++11 tries to be that way, because compatibility. Python, go, Haskell are much cleaner than JS. I'm not claiming that those languages are perfect, they definitely aren't, but there is a significant difference - just as in the saying that [earth is flat] is wrong, [earth is a sphere] is wrong, but they're nowhere near equally wrong.