3 ms·
I'm aware of what the difference is. But, and this is really important, you cannot gloss over the static nature of overloaded methods. You say "if someone add
by taeric 9y ago
I'm aware of what the difference is. But, and this is really important, you cannot gloss over the static nature of overloaded methods. You say "if someone adds a more specialized overload, it will be called", but that is only true if they recompile.
Generic functions in LISP are another way of doing this. It works at runtime, as well. And that leads to a good article in the elisp manual (https://www.gnu.org/software/emacs/manual/html_node/elisp/Generic-Functions.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ge...) that shows multiple dispatch being a runtime thing even way back. So, again, I'd be interested to know sources that said multiple dispatch was the same as method overloading.
I think I can see where overloaded methods were likely coopted by single dispatch statically compiled languages. But, honestly, I don't see how "multiple dispatch" would have ever made sense in those cases, either.
- andreasgonewild 9y agoNo one said a recompile wasn't allowed, plenty of things aren't possible in C++ without a recompile. All I'm saying here is that when you don't need polymorphism, which should be most of the time; overloaded functions do the same thing.
- taeric 9y agoWhat folks are saying is that if it is a single dispatch, but based on the parameters, it is not multiple dispatch. Literally count the number of dispatches. If it is a single, it is not multiple. I'm somewhat goal shifting by pointing out that with this you can get dynamic behavior without a full recompile, but really only a little. The entire point of this behavior is that the link in to the method is statically known to a point that can then do another dispatch where it will go to the correct place. The visitor pattern is a somewhat ugly way of accomplishing this, true. But it is absolutely more powerful than method overloading.