7 ms·
If you eliminate polymorphism and inheritance, is what's left really all that useful?
by macintux 8y ago
If you eliminate polymorphism and inheritance, is what's left really all that useful?
- kazinator 8y agoThe one we can dispense with is encapsulation. Polymorphism, no; I mean, how can we substitute different kinds of objects into the same situations dynamically without polymorphism. OOP is almost synonymous with polymorphism. But we do not have to bundle code and data representation together; there are other approaches to OOP, like generic functions.
- yourbandsucks 8y agoI mean, you can do pure functions. And those pure functions can operate on structs. And, once you're there, it's probably good hygiene to keep all the functions operating on a given struct in one file. Congrats, you're back to 'encapsulation'! Encapsulation is actually the only important tool in that particular toolkit. We're mortals, we need coping tools to keep programs manageable.
- erikpukinskis 8y agoWould you be interested in doing a podcast together about programming? I'm a radical javascript programmer (search ONNEMI-4211). You seem smart. I've never made a podcast before.
- yourbandsucks 8y agoOn the one hand, you've got some amazing satire here, on the other hand, I'm a little insulted that it's directed at me of all people. Upvoted anyways :)
- erikpukinskis 8y agoSatire?
- TeMPOraL 8y agoThat kind of "encapsulation" is simply storing code together with the data it belongs to (good practice) and possibly namespacing it together. It's not what they mean by "encapsulation" in OO courses, though it's arguably the only benefits "encapsulation" give you.
- mikekchar 8y agoI don't think we can dispense with encapsulation and still have OO, though. Sure you can program without it. You can even make good programs without it. You may even be able to make better programs without it :-) However, it won't be OO. The idea behind OO is to move away from data-centric programming. If I have a system dealing with geometry, I can have a Point object that has an x and y coordinate. However, once I have a Point, I should be trying to make my system so that I no longer access x and y directly. X and y are "encapsulated" in the Point. Collaborators should use the functionality on Point to do what they need to do, rather than trying to pry Point apart and get at the data. Of course, barely anybody writes "OO" code like that, even if they espouse to follow "encapsulation". I would argue as well that generic functions do not, in themselves offer an OOP environment. You need one more thing: partially applied functions. If you can create a partially applied function, you can bake in some program state and pass it around, offering functionality on that program state. However, nobody on the outside can access that state. This is the encapsulation necessary for OO.
- deleted 8y ago[deleted]
- jnwatson 8y agoPython is build entirely around the idea that encapsulation is mostly useless. "We're all consenting adults" is the general philosophy. As long as there's a convention as to what properties are "public" and which are not, a motivated user of a class should be able to do what they want with it. There's no point in putting a "private/public/protected" security model in a programming language. It isn't a security boundary. This vastly simplified the design of OO in Python, and it makes testing far far easier. There's no need to go through the dependency injection acrobatics in order to change one method for testing or proxying. (There technically is a way to munge a property name in Python but its use is discouraged).
- scarface74 8y agoThere's no point in putting a "private/public/protected" security model in a programming language. It isn't a security boundary. It’s about intention. If I mark a property or method as private, it means that I can get rid of it, rename it or change the expected behavior without considering it a breaking chance.
- maxxxxx 8y ago"The one we can dispense with is encapsulation." To me this is the most important part. I like to have private or public, protected is not needed. I agree that code representation should be kept separate.
- masklinn 8y ago> To me this is the most important part. I like to have private or public, protected is not needed. OO's encapsulation is about bundling data and operation, not about information hiding, and as kazinator noted generic functions (as in CLOS) prove you can have OO just fine without. As to information hiding, there are many fine OO languages which don't have it either (Python probably being the prime example there, but I'd say it also applies to languages like Ruby where you can trivially override existing ACL) so it's clearly not necessary either, let alone "the most important part". Especially as conversely many non-OO languages do have access control, hinting that the two are quite likely orthogonal. Information hiding is useful for engineering and resilience, not for object orientation. As to private / protected / public, I'd argue it's private which is the least useful (since we've already ascertained none is actually needed): it's literally just hiding stuff from yourself. I think removing that level of ACLs is one of the few good idea Go had.
- TeMPOraL 8y agoACLs also seem to mix concerns. The "private" concept is essentially making life difficult for yourself, but having a built-in mechanism for separating public interface from internal code, that's a bit more than just convention, is useful. For instance, in Common Lisp there's no language-enforced ACL, but when building modules (that may or may not involve a class, or many classes), I assign a package for each module and make it export only the symbols that represent its public interface. In code using that module, this becomes a syntactic difference in a way you refer to these symbols - module:foo means "foo exported from package 'module'", while module::foo means "foo internal to package module". That simple isolation, completely overridable with an extra colon character, is enough to clearly communicate what is and what isn't a part of an abstraction.
- mschuetz 8y agoI like to use classes almost exclusively as a way to couple an object with methods directly related to it. Basically structs with methods. Useful enough for me.