DEV Community

Bruno Noriller
Bruno Noriller

Posted on • Originally published at Medium

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!

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.