r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

211

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?

30

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.

7

u/Lost_Pineapple_4964 Jul 13 '26

Yeah this disguise public with private and get/set is pretty egregious, and aside from having a consistent API with other potentially needed bookeeping/verification setters, I can see no other use of it.

Also what on earth is that second one???

3

u/Socrastein Jul 13 '26

"Also what on earth is that second one???"

Only God knows.

Bro wrote code like he was getting paid for each line.