5 ms·
> But there's good news. The era of hierarchy-driven, keyword-heavy, colored-ribbons-in-your-textook orthodoxy seems past its peak. More people are talking abou
by k3n 14y ago
> But there's good news. The era of hierarchy-driven, keyword-heavy, colored-ribbons-in-your-textook orthodoxy seems past its peak. More people are talking about composition being a better design principle than inheritance.
Huh? Is he trying to say that composition is _not_ OOP, whereas inheritance is?
I hate to break it to him, but composition is just an expression of the composite design pattern, of which OO is part-and-parcel. You can't do either inheritance or composition without using OO principles.
edit: Ok, I concede that I'm an idiot, but at least it resulted in a lot of genuine discussion.
- sp332 14y agoYou can do composition in functional style, which is not OOP. So OOP is not necessary for composition.
- jbooth 14y agoIn the linked blurb it's mentioned as an alternative to inheritance, so clearly he means it in the OOP context. (and yes, one should usually favor composition over implementation inheritance)
- deleted 14y ago[deleted]
- codewright 14y agoGiven that Rob Pike embraces neither OOP nor functional programming, one has to wonder what he really means by composition. The closest thing to composition or reuse in Go are the typeclasses and it's pretty weak. I hope he enjoys specializing his maps and reduces for every type instance. Rob Pike has in the last few years spent a lot of time complaining about the younguns and the slightly less young younguns, but I've not seen him talk in concrete terms about what he thinks the solution is. Other than, "use Go", which doesn't actually answer the questions that are raised by his complaints. Like how Go somehow supports composition in a superior way. I've spent some time with Go, built a few projects and services. I wasn't impressed. I'll just keep using Clojure and Python until Pike starts talking about what he actually means to do to solve these problems. Hickey is an iconoclast too, but he's sensible enough to stay focused on what can move the profession forward as opposed to complaining profusely on Google+ every other week. If you really want to learn something interesting, you'd be better off learning about the fundamental relationships between code, data, state, and objects such as Hickey has covered in his past talks. They're enlightening even if you don't care about Lisp and the talks themselves aren't really in terms of Clojure except to explain how it does things differently.
- btilly 14y agoConsider carefully that Rob Pike is co-author of a well-known programming language which doesn't really have inheritance, but in which composition is trivially easy. I think that he may know more about this particular topic than you do.
- seanmcdirmid 14y agoNot only that. Rob Pike is one the original Unix guys, he is also the principal of Plan9/Inferno, and its own language Alef/Limbo. But appeals to authority are very shallow arguments. He should still be able to out debate someone who doesn't know who he is.
- btilly 14y agoAgreed. If Rob Pike were in this discussion, he would be able to do so. Heck, I could debate the merits as well. However sometimes it does make sense to appeal to authority, if only to let someone know how far out of their depth they are.
- abraininavat 14y agoNo, it doesn't. You show someone he's out of his depth by attacking his argument, not by pointing out that the counter-argument comes from someone famous. Are you seriously claiming that no one you've never heard of can possibly argue against a point made by someone you've heard of? That's a sheepish mindset.
- btilly 14y agoI actually did address the point as well. The fact that Rob Pike wrote a usable language that is not OOP in the sense that the commenter thinks of OOP, in which you have composition without inheritance is direct evidence against the commenter's point of view that to do composition you need to be doing OOP.
- pfortuny 14y agoWhat you think about someone and who Pike is I am sorry to say are irrelevant to any argument, as you probably know. Sorry could not help saying it.
- chubot 14y agoIt's a semantic argument, but composition was how people structured programs in C for 20 years before popular "OO" languages like C++ and Java appeared. Inheritance was the thing that was new in C++ and Java over existing practice. So therefore people associate OO with inheritance, which seems reasonable to me. (Academic languages have a different history, that's a different argument). To put it somewhat more bluntly: there were naive C programmers who were writing procedural spaghetti code. And then there were real C programmers who actually knew how to use composition to structure large programs. And then OO languages appeared. This caused the naive programmers to write spaghetti with inheritance. And the real C programmers were shaking their head because people already had the tools to write maintainable programs (composition), but they ignored them in favor of buzzwords and the "everything should be OO" mentality.
- k3n 14y agoThanks for the thoughtful reply, I actually learned something here. Much better than the "you're not qualified to argue Rob Pike" approach.
- chubot 14y agoGlad it was helpful. If you want to see why Unix programmers scoff at OOP, I recommend "The Art of Unix Programming" by Eric Raymond. OOP advocates threw around words like modularity and encapsulation and a lot. But nobody told programmers that Java and C++ have much worse modularity and encapsulation properties than the traditional Unix style. Ideally under Unix you would have small Java programs and small C++ programs working together and passing messages. But that's not really how a lot of people architect things these days. You tend to get monolithic Java codebases and monolithic C++ codebases. People don't design protocols with care. The web is also very Unix-y. It's structured around data and simple protocols. Yet for some reason programmers insist on "abstracting" the web with objects. These attempts have uniformly failed. There's a reason for that. On a related note, this was discussed on HN recently: http://programmers.stackexchange.com/questions/163185/torvalds-quote-about-good-programmer http://programmers.stackexchange.com/questions/163185/torval... Note that Linus Torvalds is a C programmer -- he doesn't use any "object oriented" languages. Structuring programs around data makes them modular. A main reason is that you can adapt data from one form to the other, to glue together pieces of code. You can't adapt byzantine sequences of method calls and inheritance trees -- you end up having to rewrite. Look at classes in Java programs that have the word "Adapter". Often they are a big smell and barely work, and this is because the fundamental abstractions being used are non-compositional.
- eridius 14y agoI don't think I've ever seen a language that claimed to be OOP but used composition instead of inheritance. Can you point at any examples?
- sea6ear 14y agoNot a language but a library: see SNIT (Snit's Not Incr Tcl) at http://www.wjduquette.com/snit/ http://www.wjduquette.com/snit/ is a fairly complete object system for Tcl that eschews inheritance in favor of composition.
- mixedbit 14y agoThis is also an example of composition: cat /etc/passwd | cut -d':' -f1 | sort | grep -v root | tee /tmp/users It was invented long before OOP and until today this is probably the most successful approach to code reuse.
- sukuriant 14y agoUnix arrived in 1969 according to Wiki Smalltalk arrived in 1972. That's only 3 years; and that's implementation not idea creation