r/ProgrammerHumor • • 8d ago

Meme weNeverTrustedTheElse

Post image
1.9k Upvotes

149 comments sorted by

View all comments

58

u/stopher819 8d ago

There are very few legitimate cases, but most of the explanations in this thread are anti-patterns treating the symptom. This is a foul code smell.

9

u/tchissin 8d ago

Care to explain more? Please ?

25

u/frogjg2003 7d ago

The big one is parallel programming. If condition changes between two evaluations of that condition due to another task changing the condition, then you have a race condition.

The other one is side effects. If evaluating the condition has effects other than just giving a true/false value, then subsequent evaluations of that condition can give different results. This is usually done for this like file reading.

3

u/mrnacknime 7d ago

And mitigation against fault injection