News for hackers. Stuff that matters.
Re:Java 1.0 Turns 25 by dragonwriter on Saturday January 23, 2021 @03:30PM (#25885757)
You can make member variables public, but that means that changes to how you handle access become compatibility-breaking.

If you use getters and setters, you have more future options without breaking backward compatibility. When you are making libraries that lots of other projects might depend on, this is probably more important than when making apps, especially relatively small apps.

“Getter/setter from the start” optimizes for induced maintenance cost on dependent code.

Now, in some other languages, access via getters/setters is at least source-compatible with field access, which makes this less of (or not at all, for dynamic languages, or if it is object and not just source compatibility) an issue. But that's not the case with Java.

Re:Java 1.0 Turns 25 by acdha on Saturday January 23, 2021 @04:14PM (#25886162)
> When you are making _libraries_ that lots of other projects might depend on

I think that's the key part here: most developers are writing code which will rarely or never be reused but they _learn_ by looking at shared code, and shared code which is on a different development cycle by a team nobody knows, and the field doesn't hasn't had a great history of discussing how different tradeoffs are appropriate for different projects.