Hacker News new | ask | show | jobs
by xboxnolifes 384 days ago
> Most data structures have invariants that must hold for the data structure to behave correctly. If users can directly read and write members, there's no way for the public APIs to guarantee that they will uphold their documented API behaviors.

You can, just not in the "strictly technical" sense. You add a "warranty void if these fields are touched" documentation string.

2 comments

That's honestly horrible. It's like finding your job is guaranteed by a pinkie promise, or the equivalent.
Most of the world runs on a handshake.
That's not a valid argument. For most of human existence there was cannibalism and/or human sacrifices. This doesn't mean we should go back to it.
isn't that the norm in many places on earth?
I prefer liability when devs misuse software with consequences for society infrastructure.
A language adding private fields does not add liability.
Indeed, misusing the library and causing software faults does, so every stone in the way preventing misuse helps.