One “IF” to rule them all

Bruno Noriller - Nov 11 '23 - - Dev Community

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!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .