4 ms·
IMO the biggest problem, even worse than type coercions, is the error silencing regarding wrong argument counts. This can easily hide so many bugs, it's amazin
by Peaker 12y ago
IMO the biggest problem, even worse than type coercions, is the error silencing regarding wrong argument counts.
This can easily hide so many bugs, it's amazing it is acceptable to anyone.
- Kiro 12y agoDo you have an example?
- Peaker 12y agoCall a function "foo" that expects 3 arguments with 5 or 2 arguments, instead. Javascript will gladly accept that and not yield any error, not just at compile-time, but even at run-time! Unless the function explicitly checks that the argument list is correct, it will simply hide the bug. When changing function signatures in any language, it is the programmers' collective responsibility to fix all callers (some of which in the same working tree, some hidden in others' branches, etc). In a static-language, it is very easy, you get compile-time errors at some point. In dynamically typed languages, it is slightly harder -- you get an error (ideally under a test suite) and fix it there. In Javascript you get cryptic bugs. No compile-time error. No run-time error. Happy debugging!
- implicit 12y agoGuess the result of this fragment: ["1", "2", "3"].map(parseInt)
- deleted 12y ago[deleted]
- Kiro 12y agoOk, that's crazy. Here's the explanation for anyone interested: http://stackoverflow.com/questions/14528397/strange-behavior-for-map-parseint http://stackoverflow.com/questions/14528397/strange-behavior...
- briantakita 12y agoIn practice, this issue is rarely (like 1-2 times a year) encountered. And then functional tests catch the error. It would not be acceptable if it was a constant thorn.