💾 Archived View for yujiri.xyz › software › enforced-privacy.gmi captured on 2022-07-16 at 14:27:44. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-06-03)
-=-=-=-=-=-=-
Many languages have enforced privacy: a member of a module or class can be declared "private" and that makes other code not allowed to access it. In some cases (Rust I believe) this is partly for compiler implementation reasons, but that aside, it's a stupid policy (and I'm pretty sure there are people who defend it as a policy, so I'm making this article).
Nothing in a language without enforced privacy stops you from having loose coupling and marking attributes not meant for external use with a convention like a `_` prefix. The discussion isn't about the benefits of loose coupling (those are obvious), which is why Wikipedia's car manufacturer example is a false analogy. Enforced privacy isn't about *not* accessing implementation details from the outside, but *preventing* said access.
The core reason this is stupid is because as a library author, you can't anticipate all possible use cases of your code. Just because you don't see why someone would need to access something from the outside doesn't mean there's never a valid reason. Hacks are ugly and I have as much of a negative visceral reaction to them as the next coder, but sometimes, practicality beats purity*, and so I don't understand why so many people are convinced that we should *artificially* hide data from *intentional* access.