News for hackers. Stuff that matters.
Re:Ask HN: Why do you make class members private? by jacquesm on Monday July 25, 2022 @03:35PM (#32229807)
No, it says 'this is not meant for you to change from the outside'. It's an implementation detail, not part of the interface and any references to it are bound to break without notice, warning or acceptance of the consequences.

Think of the interface to your class as a contract: this is how this class works, from now until eternity (or until the next breaking change ;) ). Relying on implementation details breaks that contract, the contract is on the interface not on the guts.

It won't be 'hard to change' it may be impossible to change. Because someone that relies on your class may not have access to the code of the other class!

Re:Ask HN: Why do you make class members private? by robalni on Tuesday July 26, 2022 @02:53AM (#32235195)
> any references to it are bound to break

Do you mean that if someone changes a class member, they would not change in all places that use that class member? Why not?

> someone that relies on your class may not have access to the code

As I wrote in the clarification, I'm only interested in cases where everyone has access to all the code.