💾 Archived View for yujiri.xyz › software › enforced-privacy.gmi captured on 2023-04-19 at 22:46:56. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

yujiri.xyz

Software

Enforced privacy is stupid

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 this is partly for compiler implementation reasons, but that aside, it's a stupid policy (and 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.

Zen of Python

contact

subscribe via RSS