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

Yes, java would be a mess without overloading (particularly for telescoping args), but that's because it doesn't include other, simpler features that address the same problems. Namely:

- default parameter values

- union types

- names arguments

I would also throw in list and map literals, to do away with something like varargs.

All of these are much simpler, implementation-wise, than method overloading. None would require anywhere near the compiler or bytecode-level support that method overloading does. It just has a very low power to weight ratio, when other langauge features are considered. And, unfortunately, it makes implementing all those other features (useful on their own) extremely difficult.




I don‘t really see a significant difference between overloaded methods and a single method with a sum type (where, in the general case, the sum is over the parameter-list tuple types of the overloaded methods). One can interpret the former as syntactic sugar for the latter.


Static vs dynamic dispatch, to start with.

You need default values (and ideally named parameters) to really make them equivalent, but yes, both address a similar set of developer needs.

The java implementation, where it bleeds into bytecode and method scoring in insane ways, is particularly unfortunate.


But it’s not actually syntactic sugar in java. There is a whole concept of type-signature which is part of method look up.

Without overloading lookup would just be via name.


On the other hand languages get by completely without method overloading and use for example default parameter values.

I don not think that method overloading is necessarily required to not make a mess.




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

Search: