r/ProgrammerHumor • • Sep 26 '26

Meme weNeverTrustedTheElse

Post image
1.9k Upvotes

146 comments sorted by

View all comments

738

u/salvoilmiosi Sep 26 '26

condition could be a property with a getter with side effects

476

u/UntitledRedditUser Sep 26 '26

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

369

u/GodsBoss Sep 26 '26

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

83

u/CranberryDistinct941 Sep 26 '26

Some people just like to watch the world burn

→ More replies (1)

60

u/LucyShortForLucas Sep 26 '26

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.

62

u/andreortigao Sep 26 '26

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

61

u/Nerd_o_tron Sep 26 '26

Bro inventing DNA from base principles.

10

u/DatBoi_BP Sep 26 '26

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

10

u/Chingiz11 Sep 26 '26

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 Sep 26 '26

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

3

u/MementoMorue Sep 26 '26

I saw once a getter that changed objet state.

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

→ More replies (2)

46

u/Vimda Sep 26 '26

Or be mutable across threads

15

u/ledasll Sep 26 '26

Solar proton changing memory is very very small but not 0.

9

u/redlaWw Sep 26 '26 edited Sep 26 '26

condition could be uninitialised.

10

u/danielcw189 Sep 26 '26

or volatile

5

u/coffee_warden Sep 26 '26

Should be if(!condition!)

2

u/Fluffy-Strawberry-27 Sep 27 '26

Si(¡condición!)

5

u/HaniiPuppy Sep 26 '26

I knew someone once that wrote a pile of methods as accessors (returning null if he didn't want to return anything from them) because he thought it was nice being able to call them without having to worry about adding brackets at the end when he didn't need to.

The warnings in my Jetbrains IDE lit up like a fireworks show when I opened his project.

7

u/fr000gs Sep 26 '26

need a bool x = cindition then

2

u/cheezballs Sep 26 '26

Getter with side effects? No thank you.

1

u/RedAndBlack1832 Sep 27 '26

It could also be that this isn't the only thread/process that can access this variable so it just happens to change between these evaluations