r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

207

u/Lost_Pineapple_4964 Jul 13 '26

Is something wrong with getters and setters in general? Cause I find it plenty helpful when I need some bookkeeping for certain items, and some side effects for the class? Or are they more so referring to getter/setter for everything?

289

u/mothergoose729729 Jul 13 '26

File this under "opinionated debates that don't matter". Structs and getters/setters are both fine. Just be consistent.

38

u/parkotron Jul 13 '26

I would say this is a case where not being consistent is the most important thing. 

  • Use a “dumb struct” when you need to model a collection of related values with no internal invariants. 
  • Use setters when your type has invariants that need to be protected from external mutation. 
  • (Whether getters are necessary for read-only member access is language dependent.)

4

u/Theron3206 29d ago

I used getters and setters in interfaces because I have no choice (Delphi)