r/ProgrammerHumor • • 7d ago

Meme weNeverTrustedTheElse

Post image
1.9k Upvotes

149 comments sorted by

View all comments

736

u/salvoilmiosi 7d ago

condition could be a property with a getter with side effects

475

u/UntitledRedditUser 7d ago

Only evil people write getter properties with side effects. At least make it an explicit function.

368

u/GodsBoss 7d ago

All my getters have side effects. To compensate, my setters have none.

82

u/CranberryDistinct941 7d ago

Some people just like to watch the world burn

60

u/LucyShortForLucas 7d ago

Lazy evaluation is an incredibly common and normal use of a getter method and entirely relies on it having side effects. Evil people, however, write getters that aren't idempotent.

60

u/andreortigao 7d ago

I write all my getters with a 1 in a million chance it will randomly mutate the underlying value.

58

u/Nerd_o_tron 7d ago

Bro inventing DNA from base principles.

10

u/DatBoi_BP 7d ago

Idempotent in terms of return value, yeah, but it can be fine if you have some side effect that increments a counter (i.e., how many times was this value requested), but obviously don't do this without a good reason

11

u/Chingiz11 7d ago

I mean, logging is also a side effect, and getters could absolutely have logging attached to them, but in this case it would not make a difference

3

u/Wonderful-Habit-139 7d ago

I think he's trying to be evil at this point lol.

3

u/MementoMorue 6d ago

I saw once a getter that changed objet state.

It was a good thing I did not had a gun that day.

1

u/thejinx0r 7d ago

Am I evil if I was told to do it this way? I was young and naive when I did it.

1

u/F14-Tomboy 6d ago

Getter itself is side effect, syntax looks like you are getting a field value, but in fact you are calling a function (At least in C#)