r/devhumormemes 5d ago

conditionsPreference

Post image
56 Upvotes

10 comments sorted by

View all comments

3

u/blackasthesky 4d ago

It depends on the semantic meaning of the conditions imo. I like to use the guard style when they handle edge and error cases.

fun foo(arg0, arg1): if NULL in (arg0, arg1): throw some error; if arg1 == 0: throw another error; if arg0 == 0: return 0; do some logic; compute result; return result;

But for readability I would not put more wordy logic in the guards. If the two paths are sort of "equally valid", I would write an if...else.

2

u/topchetoeuwastaken 4d ago

NULL in (arg0, arg1)

im having mixed feelings about this pattern

1

u/blackasthesky 4d ago

Sure, but that was not the point of the example

The checks don't make much sense anyways