6 ms·
method overloading is a horrible language feature that papers over the absence of other, more useful language features like optional arguments, etc. i worked o
by recursivedoubts 5y ago
method overloading is a horrible language feature that papers over the absence of other, more useful language features like optional arguments, etc.
i worked on a JVM programming language back in the day, and that damned feature screwed up everything: method resolution was obviously a pain, but it got involved in generics, class compatibility, it even ends up worming its way into bytecode, since methods names are really the name plus the fully qualified type name of every argument (even if there isn't any method overloading for a given method, just awful)
i wrote an old blog post on this:
https://guidewiredevelopment.wordpress.com/2009/05/22/i-am-hate-method-overloading-and-so-can-you/ https://guidewiredevelopment.wordpress.com/2009/05/22/i-am-h...
in conclusion: things should have unique names
- usmannk 5y agos/principals/principles in the post
- recursivedoubts 5y agoi wrote the post 13 years ago and no longer have access to that blog i'm shocked it's still up, tbh
- adgjlsfhk1 5y agoIt might be annoying to implement well, but there's a reason no widely used programming languages (other than assembly) have add_int and add_float as separate functions.
- skitter 5y agoI don't know GScript, but wouldn't it be enough to know which methods are declared in GScript (and not allow overloading for these)? Then type inference can work fully most of the time and only give up when calling non-Java code. Also, why does this complicate the parser? It looks like you're interfering some type information from later usage (the `foo( someVar )` example), so handling typing in the parser seems a bit strange. As for the bytecode, it's not just methods: Fields likewise are identified by name and type and can be overloaded. I'm just happy that Java itself doesn't allow field overloading - I'm not the biggest fan of method overloading either.
- recursivedoubts 5y agothe parser gets more and more complicated as you score methods, this gets really, really, really nasty once generics get involved just an awful feature that solves no problems that can't be better done with other features that, for whatever reason, just aren't as popular
- adgjlsfhk1 5y agoHow else would you implement addition? What is another API that can handle adding objects of various types, (Int8,16,32,64, BigInt, Complex for all of these, rational for all of these, and Float16, 32, 64) that doesn't totally suck?
- recursivedoubts 5y agounion types
- DNF2 5y agoFirst of all, Julia does have union types. But how does that help when the caller gives you a user-defined type?
- recursivedoubts 5y agow/ proper union types, you just chuck another type, user defined or not, in the method signature and type cast via whatever syntax you have available in the implementation
- DNF2 5y agoSo you live in a world where there's a fixed number of built-in types hard-coded into your library? I'm afraid that doesn't cut it in a modern programming context.
- adgjlsfhk1 5y ago
- DNF2 5y agoMultiple dispatch with external methods isn't a 'feature' of Julia, it is the central organizing principle that the whole language is built on. And among everyone who actually uses the language there is consensus that it is what makes it good. Sorry to hear that you failed to implement it back in the day, but that doesn't mean there's anything wrong with multiple dispatch in and of itself. It's just hard to get right. But when it works, it is without doubt the best paradigm for a language that I can think of. BTW, optional arguments are not 'absent' in Julia, they are absolutely present, and are, in fact, implemented using multiple dispatch.
- eigenspace 5y agoDynamic dispatch is not the same thing as overloading. You can't achieve the same thing by fully qualifying the name of everything statically.