DEV Community

Cover image for IPAT -  A New Principle I'm Following
ᴋᴇᴠɪɴ ᴘᴏsᴛᴏɴ
ᴋᴇᴠɪɴ ᴘᴏsᴛᴏɴ

Posted on

IPAT - A New Principle I'm Following

One of my least favorite code review comments to give or receive is

"This is great, but we already have code to do this over here..."

Don't get me wrong, I'm glad the comment happened when it did. It is better than never getting it, but think about the time that was just lost. 😱

As the reviewer, I treat this as a smell. What can we do better to make this reusable code more obvious?

Better documentation?
Better use of well known patterns?

As the author, I feel lazy. How did I miss that we already do this?

I am new to my current codebase, and I have had this happen a few times already. I knew the codebase at my previous company like the back of my hand. I would tell new folks to assume the code you need to write is already there. Sometimes it is true, sometimes not. But it was a healthy assumption that saved them time and cut down on unwanted duplication.

Need to write a new test helper for your situation? It's probably already there. Need to sanitize these params in a certain fashion? It's probably already there. Need to do [insert some complex domain thing]? It's probably already there.

I'd like to introduce a new principle that I'm going to start using more often.

IPAT - It's probably already there.

One of the largest detractors to a maintainable code base is duplication. It's also one of the most frustrating things for new folks.

"Uh, which one of these ways is the right way?"

Having this principle of IPAT on the mind helps reduce adding yet another way to do the same thing. It also gives you a reason to search through the code base more, which as a noob, you learn to appreciate.

If we are being honest, we should be doing this already, and most of you probably already do. But I suppose that's the point of principle mnemonics right? They help us to remember things that usually serve us well.

For the well actually crowd...

Isn't this the same as DRY?

No. The DRY principle is one to consider when you are about to knowingly duplicate code. IPAT is about assuming what you need is out there somewhere so that you don't mistakenly duplicate. For another blog post, but there are absolutely reasons to repeat code.

Isn't this the same concept as "Don't reinvent the wheel?"

Yeah, kind of. But I like IPAT a lot more that DRTW. 🤷‍♂️

Discussion (0)