How To Decouple Code

I’ve been stuck on an entire code base for way to long now. The problem is simple to state. It is really hard to test. It could be worse though. It could be hard to test and totally broken! But that is not the case. The code is wildly successful, but the problem is nothing is getting easier. That is to be expected in the sense that the code will inevitably become more complicated. At the same time, the refactoring has been slow coming and is difficult to do in small atomic bits.

The question then is how do you decouple things. They tell you in school to write decoupled, yet cohesive code, but what happens when you have some code that managed to get coupled pretty extensively. How do you take a huge amount of code and make things more isolated and in turn testable? I should mention there are already tests. I should also mention, again, that the code works extremely well. We are not talking about code that doesn’t get the job done. We’re talking about code that gets the job done very well thank you very much.

The real problem here is that it is not just the code that needs refreshing. It is my own experience as a programmer. I’m becoming more attuned to the value of real object oriented programming. Testing is clearing becoming more and more important in my day to day life. I want to write better code and I’m learning things to help me do just that. The problem though is that the code I stare at all day long isn’t helping me use all this new found knowledge.

My only tactic is to dive in. Start tearing apart he code line by line. I’m trying to simply organize things differently and see how it looks. There is obviously a reason they call them text editors after all. I’m not writing new code. It is just editing what is there.

I should also mention that none of this bothers me in the slightest.

This kind of struggle is what programming is all about. Some people need to solve huge scaling issues for the first time while others need to take already scaleable code and improve it via an updated version of some library or tool. It is all a part of the job. This is also not a rant against the original author! I’ve intentionally mentioned it worked and scales really well consistently and on purpose. The code is not the “problem”. The problem is I’m still learning how to improve the code and make it truly better.

It all might be a pipe dream and the fact of code is that it gets uglier with age. If that is the case, so be it. But at least I’d like to prove it. If not mathematically (like that would even happen!), but to myself. I’m perfectly willing to accept something is a hard problem and that is just the way it is. At this point though, I’m pretty sure it is just me that needs to learn a few more tricks. The title of this post is really a question. I hope folks consider offering some advice in the comments.