4 ms·
This may be a bit pedantic, but OOP != inheritance. Inheritance is the worst part of OOP. OOP is also modules and namespaces and encapsulation, all of which are
by jgwil2 6y ago
This may be a bit pedantic, but OOP != inheritance. Inheritance is the worst part of OOP. OOP is also modules and namespaces and encapsulation, all of which are great.
- bccdee 6y agoI don't think modules or namespaces really count as OOP. And encapsulation can exist in the absence of OOP if the privacy barrier exists at (eg) the module level instead of the class level. I'd argue that inheritance is really the core of OOP (and by extension methods, which are only different from functions insofar as they interact with inheritance).
- petr25102018 6y agoHow are modules and namespaces OOP?
- jgwil2 6y agoTo me OOP is about separation of concerns, abstract data types, information hiding. Modules/namespaces support decomposition the same way that objects do, and historically they became popular because of and in tandem with object-oriented languages. So it's true as others have pointed out that they can and do exist in other paradigms; I would argue that is evidence of the influence of OOP and the fact that its best ideas have been incorporated all over the place.
- bccdee 6y agoThose are just good programming principles in general though. Abstract data types, information-hiding, and separation-of-concerns were being done in C well before OOP was a thing. Granted, the information-hiding wasn't as sophisticated as it got once OOP was introduced, but I don't think it makes sense to attribute information-hiding to OOP as a result, especially since newer programming language have used visibility attributes in the absence of OOP classes.
- abecedarius 6y agoSome would say abstract data types are not OOP -- OOP is defined by how it's different from ADTs: https://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf https://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf
- cogman10 6y agoBy and large, I think inheritance is a major mistake. Interfaces are the only "good" part of inheritance. Sure, there are edge cases where inheritance is truly the best way to do things, but those are few and far between. I cringe every time I dive into some of my day job's more deeply inheritance based code. It is SO hard to make changes there without breaking a bunch of stuff unintentionally.
- abecedarius 6y agoThe way I'd put it, the mistake was to make inheritance the default. It's a sometimes useful mechanism (called "open recursion" in the FP world).
- BerislavLopac 6y agoIronically, in Python you can use interfaces without ever resorting to inheritance. :)
- cogman10 6y agoTruly a description of dynamic typing :) Interfaces without declaration.
- BerislavLopac 6y agoI didn't say that they were not declared. You can have proper, type-checked and runtime enforceable interfaces, without having to inherit from them.
- spaetzleesser 6y agoAgreed. Inheritance CAN be very useful but I would consider it an advanced feature for special cases. It’s definitely not something that should be taught to beginners.
- socialdemocrat 6y agoThings which all exist in non-OOP languages and before OOP became a fad. No OO isn't inheritance, but implementation inheritance is one of the few things which is unique to OOP based programming. Most other aspects of OOP will be found within other paradigms. More importantly OOP is not merely a bag of syntax and features but a way of thinking about software development and structuring your programs. OOP says you organize your code around objects and the actions done on those objects. That is something I find that often isn't a great way of structuring your code. But I don't think OOP is useless. I do use OO thinking in my code, just not as much as I used to. I prefer functional thinking. Often I organize code arounds verbs rather than nouns. So one file may be a similar kind of action performed on many different kinds of objects. E.g. when writing a rocker simulator, I would have one source code file which contained mass calculations for a variety of objects. Another file would contain rocket thrust calculations. I would say though that in GUI programming I find that OO thinking tends to make a lot of sense.