3 ms·
The author recommends watching Object-Oriented Programming is Bad.[1] I did, and Brian went into a discussion of dependencies (at ~20 minutes) and the implicit
by a_wild_dandan 7y ago
The author recommends watching Object-Oriented Programming is Bad.[1] I did, and Brian went into a discussion of dependencies (at ~20 minutes) and the implicit state-sharing that destroys real encapsulation and makes OOP a nightmare. He says: So if we're taking encapsulation seriously, the only real way to structure a program -- to structure objects as a graph -- is not as a free-form graph, but as a strict [tree] hierarchy." We handle message calls from one node to another by drilling messages from The Root down to the other ancestor. "No one writes programs this way."
We do. It's called Redux. The state is a tree, and each child is immutable and calculated via a pure function of the state and action (called a reducer). A message (called an action) propagates down every branch, and most ancestors remain unchanged, as they don't care about that particular action. So you have an explicit ledger of how state has changed, and figuring out why is trivial. State as an immutable result of pure functions gives you features for "free", e.g. time-traveling through your state. Debugging is a breeze. It's an absolute godsend.
(I realize the video is from 2016 and his opinions might've changed, but I think the speel is still valuable here.)
[1] https://www.youtube.com/watch?v=QM1iUe6IofM https://www.youtube.com/watch?v=QM1iUe6IofM
- lewisjoe 7y agoYes, redux is a much saner way of mutating state, but the pattern is closer to FP than OOP. Remember Brian isn’t attacking state-management in the front-end or anything specific. He’s attacking the entire paradigm of object oriented programming.