4 ms·
The biggest gain for large pieces of software from OOP is encapsulation, But before OO languages became popular, people encapsulated data by using opaque point
by danieldk 14y ago
The biggest gain for large pieces of software from OOP is encapsulation,
But before OO languages became popular, people encapsulated data by using opaque pointers. It can be argued that OO-programming promotes encapsulation, but in practice it is not hard to accidentally leak the internal state of data (especially in languages that only provide boxed data types).
Also, in (some) functional languages, encapsulation is comparably obtained by not exporting the constructors of a data type.
So, I am not convinced that encapsulation is in any way an exclusive or even defining property of OOP.
- debacle 14y agoThat's all well and good, but that's not what wikipedia says.
- simonbarker87 14y agoAre you implying that wikipedia is the authority on all topics? Given it can be edited by anyone at anytime I would suggest that comments on HN or elsewhere are no more or less valid than what wikipedia says
- debacle 14y ago> comments on HN or elsewhere are no more or less valid than what wikipedia says I'm not going to be dragged into a discussion based on such a ridiculous premise.
- seanmcdirmid 14y agoOOP is defined primarily by its ability to abstract and encapsulate data (and state) in objects. See William Cook's paper on "On Understanding Data Abstraction, Revisited." Of course, there are other ways to encapsulate state; e.g., as monads; OOP doesn't promote encapsulation so much as it promotes encapsulation using objects. The second defining aspect of OOP is messaging (goes along with encapsulation); Alan Kay has more to say about that (just check out Message Passign on wiki). The third is probably dynamic dispatch and polymorphism; not all OOP languages have that. I've dealt with plenty of weird non-procedural OO languages (including my own) with no recognizable procedure construct, but this is a much more controversial position as there are no mainstream non-procedural OOP languages out there (Erlang?). However, procedural programming is mostly orthogonal to OOP, which is what I think the blog post is trying to get across?
- danieldk 14y agoOOP is defined primarily by its ability to abstract and encapsulate data (and state) in objects. I cannot help but thinking this is a tautology: 'Programming with objects is defined by putting data in an objects.' What is an object? How does it defer from other data structures where its members are hidden to the outside world? I am not arguing that OOP does not exist, just that one aspect that has always been touted as one of its greatest advantages, also exists in most non-OO languages. The second defining aspect of OOP is messaging (goes along with encapsulation); Alan Kay has more to say about that (just check out Message Passign on wiki). The third is probably dynamic dispatch and polymorphism; not all OOP languages have that. Is message passing without dynamic dispatch and polymorphism really message passing? (In contrast to a function call that has a structure as an implicit argument?) there are other ways to encapsulate state; e.g., as monads A data type is a monad if a function is provided that defines how computations of that data type can be combined[1], and that function obeys the monad laws. A monad can be used to combine effectful computations (IO, ST) or threading state through function calls (State). But e.g. the list, Maybe, or Either monads have little to do with state. [1] Excluding 'return' for brevity ;).
- seanmcdirmid 14y agoMonads can be used to encapsulate state, they are used for other things. You can use objects to encapsulate state, or you can use another style of data abstraction, whatever floats your boat. OOP has no unique capabilities, you just get to design your programs around objects, which is good enough for me. Its all about design.
- deleted 14y ago[deleted]