4 ms·
Implicit casts are both convenient and evil. JavaScript deserves its own place for it. I've never understood why any language does this. To save a few keystrok
by chopin 7y ago
Implicit casts are both convenient and evil. JavaScript deserves its own place for it.
I've never understood why any language does this. To save a few keystrokes? Code is much more read than written.
- rocqua 7y agoIn most cases, up or down casting 32 and 64 bit integers would be a shitton of work that barely adds anything. A similar case could be made for casting ints to floats (i.e. 2 + 3.1 should just work). Beyond that though, most implicit casts are just bad.
- Izkata 7y agoJavascript and PHP deal with HTML, where input forms can only request text* but are often used for numbers, so the conversion rules are an attempt to automatically treat numbers as numbers instead of forcing programmers to always do the conversion themselves (as other frameworks rely on instead). With this kept in mind, I've personally found almost all the implicit conversions in both languages to be intuitive. * You can limit the values to numerics, and nowadays use attributes to handle javascript, but that wouldn't help PHP where it gets encoded to querystring anyway.