DEV Community

Bruno Noriller
Bruno Noriller

Posted on • Originally published at Medium

5

One “IF” to rule them all

There’s a lot of code to write, many times we just duplicate, and sometimes we do it DRY and others WET.

But the nasty of them all is when you just keep popping with “if” this, “if” that and keep repeating the same things over and over.

Needless to say, the nightmare is when some “ifs” need to be with even more “ifs” and then you have to change the “if”.

One “IF”

There are many ways to handle that, multiple patterns, but there’s nothing better than abstracting the darkness that rises in one place and then using that as the “one place of truth” for whatever that “if” is doing.

Yes, I was rereading LOTR, and well…

Three ifs for the seniors with their knowledge vast;

Seven for the mediors who code so fast;

Nine for juniors doomed to bugs;

One for the Programmer in his dark room;

In the land of programming where the bugs lie.

One if to rule them all, one if to switch them;

One if to bring them all and in the code bind them;

In the land of programming where the bugs lie.


Can do better or have others? Leave it in the comments!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (3)

Collapse
 
lionelrowe profile image
lionel-rowe

But the nasty of them all is when you just keep popping with “if” this, “if” that and keep repeating the same things over and over.

Did someone say too many if statements?

Collapse
 
noriller profile image
Bruno Noriller

I would say "ow", but sometimes when I trigger copilot, it just gives me this type of code. So...

Collapse
 
anitaolsen profile image
Anita Olsen • Edited

I love LOTR as well! One “IF” to rule them all! Love your writing. I saved this for later.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay