If-Else Might Not Be The Devil

Adam Presley
The Startup
Published in
4 min readJan 29, 2021

--

Photo by Alessio Zaccaria on Unsplash

You’ve seen the articles. “Don’t use If-Else”, and “Here’s a design pattern to stop using If-Else”, or Stack Overflow questions asking why If-Else is bad. I even read one article recently that said, and I quote, “But, let’s put an end to that right now, by replacing If-Else with the state object.” There seems to be some idea among some software engineers that using the If-Else construct in your language of choice is a bad thing. I submit to you, dear reader, that it is not.

Please note that this is my opinion I am sharing with you, and that what I say here does not necessarily reflect the views of my employer, my friends, my coworkers, or anyone else. Furthermore, what I talk about here does not necessarily apply to every situation. Sometimes there are very good reasons to apply some type of design pattern, or other clever bit of code instead of Ifs.

Why?

In case you have only been programming for about 1 hour, you may not know why you would need If-Else statements. Luckily that’s easy. If-Else’s are a simple way to make decisions in your code. With that out of the way, here’s why I like the good old-fashioned If-Else.

Fairly Ubiquitous

I submit to you that If-Else is a fairly ubiquitous construct. Most languages, especially imperative ones, have some concept of it. So if you…

--

--

Adam Presley
The Startup

Just a guy who loves his wife, kids, and writing software.