3 ms·
> It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base. Stupid defaults is not "the
by masklinn 7y ago
> It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base.
Stupid defaults is not "the curse of optional arguments", it's the curse of stupid defaults.
Most languages have defaults for these two operations yet have proper defaults rather than stupid ones. Python's list.sort() and int() certainly do, so do Java's Collections.sort() and Integer.parseInt().
Uniquely awful defaults is a historical (and defining) feature of javascript, not of having default values, or optional arguments.
- alkonaut 7y agoThe horror that arises in js is due to a combination of unfortunate things like function arity, and coercion. The one I was thinking of is the famous [1,2,10].map(parseInt) It’s several things that on their own aren’t mad which taken together produces a crazy result. 10 as the default for an optional second argument of parseInt is fine. But map should only use a single argument closure by default. So map(parseInt) must be equivalent to map(x -> parseInt(x)).