For My Sanity, Please Use If-Else Statements, or I’ll Find You

This prompts a door-stuck dramatic recreation

Senior Brogrammer
2 min readMay 1, 2024

I’ve seen countless blogs imploring alternatives to conditional statements or advocating not to use them in specific programming languages. Unless you have some fucking insane language that’s not used in the real world, stick to using if/else.

I’m sorry, but the one-liner question mark nonsense makes me think, and brother, I hate thinking.

Conditional statements are tools like switch or loop statements. Don’t ignore some tools because you’ve read two blogs and wanted to use your high horse writing software.

Sure, have fun Code Golfing or some other activity.

But please use if-else logic by following a few rules.

  • Fewer conditionals are easier to read, but fewer statements are even easier
  • Don’t nest, but if you must, add a fucking comment
  • It never hurts to split a conditional out into a function

For the last comment:

# What's that percent symbol mean again?
# Oh ya, looks like it's checking an even number
if x % 2 == 0:
# do y

# I know what an even number is!
if is_even(x):
# do y

You shouldn’t avoid something that makes sense in your mind. Coding for software means someone else will have to suffer.

Like anything else, use conditionals as they are a universal way to express IF something will execute.

Yes, I wrote this blog because people who write Python are scaring me.

Thanks for the read.

--

--