ASpeak IOpine!

Reasons to write bad code !!

Posted on July 12, 2008

Do you write bad code ? I hope not. I also do not write bad code. Are you trying to guess what the topic is about ? Ok here goes the story...

I was new in organization. Probably around 3 months or so. It was like any other day at office. We all were working on our modules. Suddenly something struck me. I saw a very poorly written piece of TSQL Script. The script was meant for data cutover and since the size of database was mammoth so the script was required to be efficient. However, I found so many issues. It was highly inefficient in performance.

Some of the critical issues I found were -

  1. New variables being declared and assigned unnecessarily where a single base value could have worked with reassignments and manipulations.
  2. Multiple temporary tables created and dropped for each table under process.
  3. No error handling or transaction. Single failure would make the database inconsistent.

Luckily, it was our own Dev Db which we were working on and I found this issue before it went to production. The guy who wrote this piece of code was senior to me and was a friend of mine. I talked to him and asked the reason for this inefficient design. He replied promptly saying this is the best he can do. He asked me to redo it if I could do better. I was dumb struck.

I thought why would someone write a crappy piece of code knowingly ? Either the person is incapable of this kind of job which requires a fair amount of creativity, or the person is having some serious issues. I asked him later why he is doing like that. The explanation he gave was even more disturbing.

He told me that he used to be like me once (say about an year ago). He said he was amazed to see other guys writing crappy piece of code which somehow were meeting the functionality but were nightmare for support guys and fellow coders. He further elaborated that now since he is doing the same so he understands the reason. Ahh!! the reason was that they were frustrated and overstressed of the project deadlines and work timings. He said that he releases his stress on the code. I think this is the only way he can take his revenge from the organization for stressing him out.

However, I disagree completely from this kind of approach. I believe that programming is an art and writing good code not just enhances your own skills but also helps you keeping a good practice. If you start writing bad code consistently then you would pick up that way of coding which would bite you certainly in long run.

Another aspect is the attachment with your work. I like to write good code and I make sure that every piece of creativity I apply meets the best industry standards and reflects the level of professionalism I keep striving for. Writing bad code simply because you are stressed out shows that you are not a true professional. There are ways to deal with frustration and anger but this is certainly not the correct way. Having an open discussion with the teamlead and the manager is always welcome. Bending to certain degree for the work occasionally is something that is considered quite common in our industry but if you are being pushed consistently beyond your limits then you can raise the voice instead of writing dirty code.

I learnt lessons from this experience. It would help me certainly to prevent myself from such a mental fatigue and would also prevent me from pushing my juniors to the limit where they start writing bad code !

I am sure you would have encountered such an issue in your organization or might have been the victim of pressure yourself. Feel free to share your experiences.