4 ms·
What are the reasons for keeping components of a 'thing' private? I go back and forth on this. 1. expose a clean API surface so users don't care how it works (
by quad50 11y ago
What are the reasons for keeping components of a 'thing' private? I go back and forth on this.
1. expose a clean API surface so users don't care how it works (as long as it works :)
2. make it easier to change the innards without changing its public behavior
3. keep malicious programmers from delving into the innards of our precious code.
It seems like a lot of the discussions on encapsulation (over many years) focuses on #3. Especially in the C++ and Java world. But worrying about that leads to various forms of obfuscation that make the code worse. And who cares about folks who will hack our objects? That's their problem.
- gotofritz 11y agoIt doesn't have to be "malicious" programmers. It can be less experienced, lazy, or under-pressure colleagues.