4 ms·
I'm OK with dynamic types, they buy you something, cost you something. My big complaint is weakly typed languages (I'm looking at you, JavaScript). I've just fi
by scardine 11y ago
I'm OK with dynamic types, they buy you something, cost you something. My big complaint is weakly typed languages (I'm looking at you, JavaScript). I've just fired SHIFT+CTRL+i and typed the line below in the JavaScript console:
> (1 + "1") * 2
22
At least it raises a TypeError in Python (unsupported operand type(s) for +: 'int' and 'str'). OK, probably better to fail at compile time, but I would rather fail at runtime than not fail at all.
- z3t4 11y agoIn the early days of my JavaScript'n I always used minus instead of plus when doing addition. But as the language and tools has matured I hardly see any type errors any more. I do have a habit of parseInt() that won't easily go away though :P Besides the concatenation of numbers to strings and vice versa, most other type errors in JavaScript will give you a syntax error or something like NaN (Not a Number). So don't mix strings and numbers. Everything else is just "objects". =) One thing that causes lots of bugs though is undefined object properties. But I'm not sure if inferred types would help in those cases.