|
|
|
|
|
by LBarret
5095 days ago
|
|
it is just an example, but it shows the kind of danger/potential bugs comes with using a badly designed language. PS : I know it had been designed in 11 days and as such it is an achievement, but as the most used programming language it is quite awful. |
|
The fact that we are looking at parseInt as a potential problem here doesn't even make sense, given that the way most developers at this point actually expect functions like parseInt to work is to stop at the first non-number, and the developer in this case specifically went out of their way to choose a radix where I is a number.
Things that could have happened instead:
1) parseInt could fail if it is passed a string that contains anything that is not a digit (this would surprise many developers: again, this is highly common behavior)
2) 1/0 could throw an exception (I would argue this isn't even useful: +Inf is a valuable result)
3) +Inf could return something other than Infinity if converted to a string (maybe the infinity symbol in unicode?)
4) +Inf could refuse to be converted to a string (this is awkward, given that any other number can be converted to a string)
5) numbers could always refuse to be automatically converted to strings (I actually agree with this, but I feel like I'm in the minority: 'a' + 4 + 'b' would therefore also hopefully be illegal; this is an argument for a separate string concatenation operator)
6) parseInt could specifically refuse to automatically convert its argument to a string (this is probably the most reasonable thing that could have been different; however, tons of languages, including ones considered to have amazing type systems like Scala, support implicit conversion and don't even offer this kind of override flexibity)
Which are you claiming is the bad design? Maybe there's something I'm missing? I mean, if this was a situation where 4 + '1a' yielded the result '5' I'd be sufficiently angry as to claim that the people who designed this language were incompetent or dangerously negligant (PHP probably does this... MySQL almost certainly does ;P j/k, btw, only semi-serious), but this behavior seems somewhat reasonable.