"The data needs to be protected!"
Ahahahah, yes indeed
Yup, you don’t realize it now, but that will save your ass someday.
Edit: I realized by leaving the comment above and not explaining myself, I'm also guilty of the what's in the meme, so let me add my perspective.
A simple example: imagine someday you need to constraint the value of X to be between 1 and 10. Adding this constraint in the setter is is. Fixing all cases of "x =" is harder. And if you're in a large code base, maybe you run into some weird edge cases where the "x = " is in generated code, the author of the code generator didn't account for methods. Or the original value crosses a server boundary, and now you are touching code in a different code base and have to think about skew issues and the order in which the code rolls out. I dunno, stuff like that.
The key is: minimize mutability. (That link is from Effective Java, which has great pearls of wisdom like this)
laughs in C
Having read my own code, I agree.
I mean, we are definitely the most dangerous
Data needs to be liberated.
Except that it doesn't protect the data. Java developers will mumble something about extensibility, but they'll never go and extend those classes.
Trust no one! Especially me!
I just took a Java class, i feel so fucking nerdy for understanding this
"We have met the enemy, and he is us."
--Walt Kelley (Pogo Possum)
"Anything could happen!" is a thing I've genuinely heard people say in defence of shit code like this.
23 more replies
If you are interested why its used - https://stackoverflow.com/questions/1568091/why-use-getters-and-setters-accessors
I love how all these convoluted patterns are simply addressing the inherent problems of OOP, then these patterns get lauded as advantages of OOP. Brilliant!
To address the comments below en masse - It's ProgrammerHumor not r/CommentCodeReview you pedants, go enjoy your weekend!
Terrible meme, but this is an excellent response. This should be the top comment.
Slacking Off at Work
Ranked by Size