Code a dirty solution first and then work on optimization

Source

Developers are always focused on writing optimized code. When we start with new projects and start coding, every step we take, we always have this in mind that we should be writing optimized code. This is something that is commonly seen among all the developers. I also had the same syndrome and still have that even today. That’s why when I start coding something I spend enough time to prepare the architecture and the approach I’m going to be taking before even I spend some time coding it.

I wouldn’t say that it is wrong but recently I had a conversation with one of the experienced architects in my work environment. I was discussing various topics with him. He is not someone with dead weight or something and he is very open to explaining tips and tricks that he regularly follows in his coding practices. It was indeed a great opportunity for me to talk in detail about certain aspects of coding with him. There are many things that I discussed with him and most of the items that I discussed definitely enlightened me.

Source

Finding the solution first

He explained to me the approaches he would be taking when he starts working on a new project. The first and foremost thing that he would do is to find a solution first for the requirement. He will not care about the optimization of code or anything. The first thing that he would do is to find a way to bring the requirement live. He told me that if the userbase is very minimal, we can even make the application live as an alpha version and gradually sit and improvise the code.

The first solution draft that we do can be a dirty code. It need not necessarily be an optimized one. This is something that I sometimes find it hard to agree. I told him my difficulty in understanding this. Usually when we sit and achieve the requirement, we already spend several hours coding and if we have to not think about optimized solution before bringing the solution, it can be something like we end up doing the work twice where it would take some extra hours to first write a dirty code and then work on optimizing the code that we have written.

Source

In my case, if I try to bring a solution with some dirty coding and make it work, I usually become lazy to work on optimizing the code that I wrote. The thought that I would get is to just let it be like that and focus on my future projects after that. This is the practical difficulty that I usually face when I start coding a new project. He told from his experience that it is always okay to spend time optimizing after having a solution in hand than spending time before the project before even having anything working in hand.

In a way, I was able to understand what he was trying to say. I have personally experienced some stress when I don’t get an optimized way to implement something. I keep trying several times until I get frustrated. But during some instances when I try to first do the dirty code and activate the solution and then work on optimization part, it is usually becoming quite relaxing comparatively because my mind will know that there is already a solution available so we are safe and all that I’m trying to do is optimization part. So, psychologically I don’t even take so much stress in such situations.

Be the first to comment

Leave a Reply

Your email address will not be published.


*