Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think most of these are spot on, but I disagree with number 12 (especially if you're writing code in a library).

It's worth having getters and setters for variables that need to be publicly accessible, even if there's no logic in them, because it gives you the option to change how that data is stored in the future and not break all the code that uses it. You want to be able to change the implementation without breaking all your clients' code!



I'm inclined to side with the author. In the 13+ years I've been writing Java, there's only been a handful of cases where I switched a field to a more complex implementation. And in all of those cases, the IDE would have helpfully pointed out where I need to update client code. I can understand the value of strong encapsulation when publishing library code, but for internal code getters and setters are usually massive overkill.

Fortunately projectlombok takes away most of this pain, and pretty much every modern language post-Java makes attributes/getters a non-issue.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: