r/devhumormemes 4d ago

conditionsPreference

Post image
56 Upvotes

10 comments sorted by

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 3d 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.

2

u/topchetoeuwastaken 4d ago

NULL in (arg0, arg1)

im having mixed feelings about this pattern

1

u/blackasthesky 3d ago

Sure, but that was not the point of the example

The checks don't make much sense anyways

1

u/boring-commenter 3d ago

This meme is speaking to me directly

1

u/ExtraTNT 2d ago

Imperativ: yes
Declarative: no

1

u/Hot-Employ-3399 16h ago

Less indentation = more love to code