4 ms·
Python's OOP is not superior to CLOS. CLOS is very full-featured. Python's OO does support features like multiple inheritance, which makes it more sophisticated
by jake_morrison 4y ago
Python's OOP is not superior to CLOS. CLOS is very full-featured.
Python's OO does support features like multiple inheritance, which makes it more sophisticated than e.g. Java.
One CLOS feature that is particularly interesting is multi-dispatch. When you call a method, most languages implement polymorphism by looking at the class of the object and call the corresponding method in the class. In CLOS, it looks at all the parameters of the method. This is similar to pattern matching in functional programming languages like Elixir.
https://lispcookbook.github.io/cl-cookbook/clos.html https://lispcookbook.github.io/cl-cookbook/clos.html
- crabbygrabby 4y agoYea I think the starting premiss here is flawed from the get go. MD is so powerful, kind of dangerous, but very powerful.
- gmadsen 4y agois that any different than function overloading?
- bananaoomarang 4y agoYes I believe because it happens at runtime. This is quite a good series of articles on multi dispatch that gets to CLOS: https://eli.thegreenplace.net/2016/a-polyglots-guide-to-multiple-dispatch/ https://eli.thegreenplace.net/2016/a-polyglots-guide-to-mult...
- gpderetta 4y agoMD is basically late binding for overloading. For example in C# can do MD with overloaded functions when the parameters are additionally marked as dynamic.
- dhosek 4y ago>Python's OO does support features like multiple inheritance, which makes it more sophisticated than e.g. Java. I’m not sure that “more sophisticated” is the right term for multiple inheritance. Multiple inheritance create all manner of challenges in understanding code. The simplest form of multiple inheritance as it’s present in languages like Perl or C++ can create hard to debug problems (I’m not entirely certain how it works in Python). That said, Java has (and has had) a restricted form of multiple inheritance for years through default methods in interfaces which allows the most useful aspect of MI—mixed in methods.
- p_l 4y agoCLOS implementation of multiple inheritance is less problematic, and usually you don't have overlapping methods involved - and if you really need to, you have interfaces to control inheritance process (including the ability to prevent multiple inheritance)
- jerf 4y agoPython may not "support" multi-dispatch, but it has the flexibility necessary to add it in if you wanted it: https://pypi.org/project/multipledispatch/ https://pypi.org/project/multipledispatch/ Other than not being built-in, that looks like it does everything you could ask for. Aaaaand... this sort of doubles as a partial answer to the original question, too. When your language is that flexible, and doing all its flexibility at run time, yeah, it's pretty hard to optimize. As a product of its time, Python is a triumph, and don't mistake what I'm about to say for it being "bad" somehow, but if I were designing a language today, even a dynamically typed language, I wouldn't even begin to design it with all the run-time flexibility Python has. As neat as "adding multidispatch" is in some ways, the capabilities in the language that allows you to add that capability at runtime comes at a staggering, staggering performance cost that a good 15 years of fix attempts has only partially and incompletely addressed. I have not used that Python multidispatch library, or even known it existed until I searched for it just now, but I'd lay money down that it imposes yet some further penalty to Python's already-expensive function call process. I don't think is was HN but I was just mentioning online the other day that dynamic scripting languages aren't just slow themselves, but also tend to encourage you to add yet more slow things on top of the already-slow things without necessarily thinking about the costs, and I'd bet this is a perfect example of what I mean. Yes, yes, very nice, very convenient, probably makes function calls another 5-10x slower than they already are. (I note the source package has benchmarks, and they are not mentioned in the README. I make the obvious inference.) And to be clear, this is not a criticism of this package, which I'm sure is as nice as it can be within the constraints of Python. It looks very nice to me. No red flags I can see. Compliments to the author on the off chance they see this; I'm not targeting this package. It's just part of the answer to why Python is so slow with this stuff.
- p_l 4y agoThe multipledispatch library is less language flexibility, and more manual slog to reimplement things thanks to being able to wrap a function with another function at definition. If we accept that as language flexibility, then turing tarpit awaits (I'm ->||<- this close to put it in the same category as COS, the C Object System, which actually handled most of CLOS)
- Saphyel 4y agoPython's OO does support features like multiple inheritance, which makes it more sophisticated than e.g. Java. Java forbidden multiple inheritance because of the function overriding or diamond problem. Also Python OO has a lot to improve.
- jake_morrison 4y agoMultiple inheritance can be confusing, but it's also powerful. There are generations of Java programmers who have decided that because Java doesn't have multiple inheritance, it must be bad. People mostly use frameworks these days, so inheriting from the framework uses up our one opportunity to have inheritance. Then when we would like to use it later to consolidate common code, we can't. Or we use ActiveRecord, but then can't actually, god forbid, model our domain using an inheritance hierarchy. At this point, I think OO has failed to live up to its promise, and I instead use functional programming and macros.