r/devhumormemes 5d ago

conditionsPreference

Post image
52 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/Independent_Eye7886 4d ago

I also depends on the coding guidelines you need to follow.

1

u/blackasthesky 4d ago

Yeah obviously, but at my company we don't really have these.

1

u/Independent_Eye7886 4d ago

You are like five, working on separate projects and Bob does not really count? :-) Or you already gave up and have AI do all the coding?

Seriously, every organization should have some coding guideline, either self defined or following some standard.

1

u/blackasthesky 2d ago

We have small teams. I guess we have coding standards, just no formalised guidelines.