Hacker News new | past | comments | ask | show | jobs | submit login

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.




In 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.


Do you have an example?


Call 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!


How is that an issue ?


How is a common change (updating a function signature) easily causing cryptic bugs rather than a visible compile-time or run-time error an issue?

Bugs are bad?


Guess the result of this fragment:

    ["1", "2", "3"].map(parseInt)


Ok, that's crazy.

Here's the explanation for anyone interested:

http://stackoverflow.com/questions/14528397/strange-behavior...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: