Handling The Junk Code

While writing applications most of us have the bad habit to abandon few pieces of code here and there in the process of optimization and performance tuning. Few lines of codes get completely replace by better ones and few need little tweaks here and there though, there is a good amount of code which is replaced by better ones not because they are useless but not suitable for that particular situation. Since we know this truth, we find it very hard to delete that code, instead we keep a copy of it somewhere in the same program in an area where few other codes are dumped. This place looks like a junk yard which has high potential but definitely not very organized one.

If somebody likes the code very much and does not want to throw it into the junk corner, they hide it under the comment section and put add a TODO or UTILS line above it, surely a very bad practice for production.


So, What to do with this Lovely Junk?

So what to do with this box full of good but unused code and where do we put it so it can be utilized in the later course of time? Definitely this box has to be kept far far away from the production code. Why? Since these codes have been replaced by others there is a big chance that the new code(generally a method, function or a Class) happens to have the same name and often same signature too. Its pretty clear that having multiple codes with same signature can have catastrophic effect in the later run when a new developer join the team.

A good solution would be to take the code away and put it in a repository where it feels safe and can be revisited and shared with other members. If the project is Open Source in nature, putting the junk code in an online code repository and in the organization’s own private code repository. One thing that has to be taken care of is that, it has to be put in a repository separate from the actual project. This will surely save time as developer does not have to re write the code again from scratch.

Happy Coding 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s