4 ms·
"The multimethod based design of the language" I've only just started looking at Python, but I wasn't aware that it has true CLOS-style multimethods (or multip
by arethuza 15y ago
"The multimethod based design of the language"
I've only just started looking at Python, but I wasn't aware that it has true CLOS-style multimethods (or multiple dispatch). I know that there are ways you can add multiple dispatch to Python - but is it really accurate to say that the entire language has a design that is based on multiple dispatch?
Note that I'd be rather pleased to find that multimethods are an integral part of Python - they were one of my favourite features of CLOS and I still miss them.
- swdunlop 15y agoI had a similar response, reading the article. Cue Inigo Montoya voice: "You keep using that word. I do not think it means what you think it means." http://www.youtube.com/watch?v=G2y8Sx4B2Sk http://www.youtube.com/watch?v=G2y8Sx4B2Sk
- perfunctory 15y agoBravo!
- berntb 15y agoWell, since this is about people not using Python 3 yet... It might amuse you to know that Perl 6, which isn't used either, has multi methods. :-) Edit: Dynamic dispatch otoh is in most (all?) scripting languages.
- draegtun 15y agoAlso Perl5 has multimethods via a Moose extension: https://metacpan.org/module/MooseX::MultiMethods https://metacpan.org/module/MooseX::MultiMethods
- berntb 15y agoOK, thanks. I must add, risking down votes in this thread, that it is fun to see Python people argue the practicality of Python 2 over the idealism/correctness of Python 3. It is very similar to when Perl people argue that CPAN (better OO with Moose, better infrastructure for modules, etc) outweigh the emphasis on simple syntax in Python 2... :-)
- sirclueless 15y agoI think "multiple dispatch" is the wrong word. "Dynamic dispatch" is a much better word for what Python does. It's a ridiculously powerful feature. It lets you wrap and replace functions at runtime, which gives you incredible monkey-patching power, which is important to people programming in the real world. My favorite example: Suppose you have a naive O(2^n) recursive factorial() function. I can write "factorial = memoize(factorial)" and suddenly your recursive calls are to my new wrapped function, which references your original implementation inside its closure. This is only possible because your recursive implementation dynamically dispatches by name. I have turned your O(2^n) implementation into an O(n) implementation. In an unsafe systems language like C, I would only be able to accomplish the same thing with some severe memory hacks, and in a language like Java or C# I don't know how I would be able to do the same thing without some serious involvement in runtime reflection tools, and maybe even some decompilation.
- arethuza 15y agoSounds like the author of the article has no idea what a multimethod actually is then. :-) Dynamic binding (in various forms) is arguably a pretty common language feature and generally nothing like as powerful as full multimethod implementations (let alone what is possible in CLOS).
- the_mitsuhiko 15y ago> Sounds like the author of the article has no idea what a multimethod actually is then. :-) The author (me) knows what multimethods are. I did however not find a better term to refer to the `iter(x)` -> `x.__iter__()` / `x.__getitem__()` concept.
- arethuza 15y agoI'm genuinely interested (not being snarky, honest) - could you explain why you think that expression has anything to do with multimethods? Like I said previously, I'm new to Python and I'm curious what that expression actually means.
- lucian1900 15y agoTo some extent, Python's methods are a lot closer to multimethods than methods in other single-dispatch languages (largely because they have an explicit self). This has the side-effect of making multiple dispatch work with the same syntax reasonably well http://en.wikipedia.org/wiki/Multiple_dispatch#Python http://en.wikipedia.org/wiki/Multiple_dispatch#Python