4 ms·
I have noticed this too; all the "functional" languages I've seen (i.e. those with immutable data) encourage working with bare data. Is encapsulation only neces
by cldr 13y ago
I have noticed this too; all the "functional" languages I've seen (i.e. those with immutable data) encourage working with bare data. Is encapsulation only necessary for mutable data?
- weavejester 13y agoI think immutability removes one of the reasons for encapsulation: controlling state change. With that gone, the disadvantages of encapsulation might outweigh its advantages in a lot of cases.
- deleted 13y ago[deleted]
- KMag 13y agoAlso note that many languages that encourage immutable data also have first-class functions with closures, which are also a very powerful tool for encapsulation and abstraction. I think lambdas more than immutability help one write clean abstractions without traditional OO-objects. See the "Lambda the Ultimate" series of papers for details.
- hexagonc 13y agoEncapsulation also helps enforce interfaces. Anything outside of an object should only interact with it via an external interface. This allows you to reason about the interaction of objects independently of the implementation of those objects. In theory, this allows you to change the implementation of an object without the interacting objects knowing, thus reducing the overall complexity of the program as well as potential bugs.