3 ms·
I have nothing against Julia, but most of those examples could have been written with singledispatch in Python. Seems a bit disingenuous to just completely igno
by danmur 5y ago
I have nothing against Julia, but most of those examples could have been written with singledispatch in Python. Seems a bit disingenuous to just completely ignore it. (not to mention the "In Python, this is solved with" type examples aren't representative of how anyone would actually write it)
- manwe150 5y agoIt looks like singledispatch is still relatively new, so it feels like that might not yet be representative either? 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
- jakobnissen 5y agoPython's single dispatch just means that if I do `foo.bar()`, the meaning of bar depends on the type of `foo`. So that is not recent, but a core part of the language. 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.
- Doxin 5y ago> you can't add new methods post-hoc to types in Python 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 >>>
- danmur 5y agoSo just to clarify since it perhaps wasn't clear, I'm talking about singledispatch from the standard library: https://docs.python.org/3/library/functools.html#functools.singledispatch https://docs.python.org/3/library/functools.html#functools.s...
- dragonwriter 5y ago> Another difference to Python is that you can't add new methods post-hoc to types in Python. Yes, you can. Heck, you can post-hoc add new methods to instances in python, too.
- danmur 5y agoSingledispatch is old, dates back to py2: https://docs.python.org/3/library/functools.html#functools.singledispatch https://docs.python.org/3/library/functools.html#functools.s... 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 https://github.com/wesselb/plum
- dragonwriter 5y ago> But the bigger distinction would be that Julia uses multiple dispatch, not just single, 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.
- oscardssmith 5y agoIs there any single dispatch language that lets you define multiple methods for a function of a tuple depending on the type of its elements?