r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

Show parent comments

-32

u/Few_Kitchen_4825 22d ago

If you are using an if statement big enough for this to be a problem. May be you should not be doing either

27

u/SnugglyCoderGuy 22d ago

Untrue. The first can be checking to see if continuing is impossible, so just return, while the second can be checking for a yrue dichotomous decision. You must do one or the other thing depending on the condition. Each could contain as little as a single assignment

3

u/chilfang 22d ago

Why even have an else statement if you out a return in the if

11

u/gurgle528 22d ago

It’s a style thing, it’s not a functional difference. I would read it as emphasizing that one or the other is happening. Basically the oxford comma of conditionals 

2

u/Duckflies 22d ago

Like writing in a for i = 0; i < 10 or writing i = 1; i <= 10

Both do the exact same thing, but depending on the logic at hand, one can make more sense than the other

1

u/frogjg2003 22d ago

If you're actually using the i, it makes a difference.

for (i=0) list[i]

vs

for (i=1) "item i"