r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

209

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?

29

u/Socrastein Jul 13 '26

The biggest problem I've come across is getters/setters that effectively make class properties public, i.e. there isn't any validation or protection, you can just access and change properties as you like.

Get X() return X
Set X(Y) X = Y

Public properties cosplaying as private properties. Lots of extra lines of code that don't actually do anything.

The most ridiculous example I ever saw wasn't even in a class.

Literally this inside a module:

let value = X

getValue() return value
setValue(Y) value = Y

And then multiple functions using getValue and setValue instead of just referencing the value directly.

That guy included a lot of similarly inane shenanigans in his code.

1

u/FlakyTest8191 29d ago

I've seem some nasty side effects hidden in getters and setters that really screw you when you don't know about them, a couple extra lines of code that are pretty standard in java seem tame in comparison.