Tweeted twitter.com/StackSoftEng/status/1071283349401022465
2 made title more appropriate
| link

encapsulating Encapsulating moving parts in OO vs minimizingMinimizing moving parts in FP

1
source | link

encapsulating moving parts vs minimizing moving parts

I am from OO background just started learning FP paradigm. Came across quote by Michael Feathers - "OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts"

What exactly he meant by "moving parts" ? My guess is that by moving parts he meant "state mutation" because FP promotes immutability and thus minimizes state mutation whereas OO does not discourage state mutation but rather encapsulate data (thus encapsulating mutating state of object)

I can feel how pure functions in FP promoting immutability and no side effects can result in better code clarity thus making it more understandable and more declarative vs imperative. Somehow benefits of similar nature is not very apparent to me in OO when mutating state is encapsulated.

For example below adapter object is accessed via public interfaces only but I still feel its state is not encapsulated because each step assumes some sort state transition in previous step and hence execute method looks imperative in nature.

void Execute(IdataAdapter adapter) {
  adapter.ReadFromSource();
  adapter.ProcessData();
  adapter.WriteToDestination();
}

OO definition around encapsulations mainly talks about data hiding and advanatges we get like changing internal data structure w/o breaking clients etc. But I would like to understand it better in context of above statement made by Michael Feathers. My question is basically - By encapsulating mutating state in OO makes code understandable in a same way as FP by minimizing state mutation ?