Does code hurts?

We all programmers have right to implement the code in our own way the only goal is we want it to run as per the requirement. At start I believed that there is nothing like good code or bad code it’s all about working and not working code. But I was wrong, there is such thing like bad smelly code which hurts, hurts you in the eye and hurts service or product for long term.

Let me simply share a very small example of taking wrong decision while writing the code and shipping it without code review which is a most dangerous step actually.

int id = Integer.parseInt(String.valueOf(Long.valueOf(pojo.geLong())));

It will take you a while to understand what above line is trying to do. You may take several minutes to figure out what can be the reason for writing such mysterious line of code.

Some of us will argue that no one can write such code but trust me such people exist on this planet earth. I am not going to blame them only it’s something that was in code since long and none of the people who checked this code tried to fix it.

This line can be fixed easily to avoid the confusion and in reasonable ways as per the code written before this particular line.

How about,

int id = pojo.geLong().intValue();

I might be wrong completely if getLong could return null. Well yes, in that case I would add null check or I’ll make sure that it does not return null for any case.

This line is not a problem who wrote it but for those who are going to understand it in future. I’ve multiple such examples which are really really disturbing and almost all the people in your team will advice you to avoid fixing this as they have fear of raising other problems in the code.

Come on! you can not hide truth for long, it may create problem in future. Good code is one of the standard you have to maintain in your product or service. The time has gone where working program was the only requirement. This is not about optimization but it’s about optimal approach of writing the code.

I’m happy that I usually take steps to fix such things and I may fail but I will get used to with dealing with buggy and smelly code which will help me to grow and I advice you to do the same as well.

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