How Julia Uses Multiple Dispatch to Beat Python
medium.com
medium.com
But the bigger distinction would be that Julia uses multiple dispatch, not just single, so the argument order does not dictate the dispatch capabilities. And it is little things like that which may sound trivial[1], but add up to be less effort to use (since there isn’t any other kind of function), which then also translated into being easier to optimize and run fast.
It may be hard to show this feature advantage in a single demo, as the advantage to this is better composability of multiple nouns and verbs in the language, particularly when pulling from multiple sources. Thus, Julia doesn’t need a different sin and np.sin function, for example, as the one function is already prepared to work for either caller.
[1] compare also len vs __len__ and __radd__ vs __ladd__ vs +, a hidden property distinction which doesn’t need to exist in Julia
Disclaimer: I work on Julia’s compiler team
Another difference to Python is that you can't add new methods post-hoc to types in Python. That's a big problem, but this has nothing to do with single/multiple dispatch. E.g. Rust has single dispatch but allows post-hoc methods.
Unless I'm misunderstanding what that means, you totally can:
>>> class Foo:
... def bar(self):
... return 3
...
>>> foo = Foo()
>>> foo.bar()
3
>>> Foo.baz = lambda self: 6
>>> foo.baz()
6
>>>Yes, you can. Heck, you can post-hoc add new methods to instances in python, too.
I definitely agree that multiple dispatch is a lot harder :). But most of the examples in the article didn't need it, and it would have been appropriate I think to show equivalent code in Python. All that article did was make me think the author didn't know Python very well.
There are several libraries for multiple dispatch too, for e.g. https://github.com/wesselb/plum
Multiple dispatch is just (or, at any rate, equivalent in function to) single dispatch with tuple types.
But, Julia does things like triangular dispatch, but the advantage there is narrower.