Home » Development » General » Reasons to write bad code !!

Reasons to write bad code !!

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.

Bookmark and Share

General ,

14 Comments to “Reasons to write bad code !!”

  1. I totally agree. Deliberately writing bad code is harmful to your coding style. If you are too stressed then how about taking a break ? I think no organization would force its employee beyond his limits. I also agree that dialog is the best way to get out of this stressful situation.
    Nice observation though.

    Keith

  2. Completely Agree with you. Putting your frustration at your work is the worst thing one can imagine. Though I am not from software industry but this kind of thing is commonplace in any industry. In manufacturing sector, workers just ignore the quality of the product if they don’t get good salaries or asked to worked overtime for low wages. This is a bad practice. Raise your voice, not your frustration.

  3. One could also take issue with your speaking of the English language. There are many errors in your post, both with grammar and syntax. So, just because we find something wrong with someone else’s work, we are encouraged to point it out to that person? How’s the dog food taste?

  4. There is also the small concern that “industry best practices” changes on average every 7 minutes. I could refactor our app and spend the next three months doing it, or i could just follow the best practice of the code I am working on, and get stuff done.

    your coworkers comment that he is taking his stress out on the code is bullshit, and you are a pussy for not telling him that. Straight up the reason he does it is because 1)a year ago that WAS they way to do it, 2)he doesnt know TSQL so he googled it and thats what he got.

    His comment was probably just his way of dealing with noobs that come in and suggest a complete rewrite (Lets use AJAX)

  5. @Keith: “I think no organization would force its employee beyond his limits.” <– unfortunately, some do. They work their employees to the core until they either leave, or breakdown and don’t come back from long-term sick leave…

  6. Thanks for your replies.

    @Matt, I didn’t use any wordprocessor for writing this article. It was written all in one go in Scribefire which doesn’t provide grammatical or lexical checking. Also, English is not my first language but I would like to improve on that. Thanks for your comments.

    @Tristan, neither I was nooby nor that piece of code was written one year back. Though, I agree to the point that the guy may not be good enough in TSQL. But as I have always followed the rule of thumb that “Not knowing is not bad, rather not having the ability or willingness to learn is more futile“. Hence, that was something that was more disturbing.

  7. I agree to Abhishek. I have seen some guys doing the same in my office as well. I will forward this link to them :)
    Thanks

  8. Well, this type of nonprofessional attitude are very disturbing for the management as well as the team lead. And more disturbing is when the employees are “thinking” that they are overstressed rather in reality. Some of them do not have the habit of working effectively for more than a few hrs and when they are pushed to increase their effectiveness, they think its overstress. The management expects to have around 4-6 hrs of effective work output from a developer’s 8 hr office time – but if they are not ready to provide that, there remains very few ways to push them.

    From your experience, what do you think is the best way to handle this kind of situation ?

  9. I’ve worked with developers who write messy code, some if it at a high standard and some not, but often quite unreadable and certainly hard to maintain.

    I’m sure a lack of time can be mentioned as the cause, but I don’t quite understand why senior developers write that way straight off the bat. Don’t you automatically indent your code and comment where you need to?

    In terms of a poor solution? Well that is also disturbing, why even go down the path of a bad solution if you know it won’t scale or will be a nightmare to maintain? If you can’t speak with a development manager (or at least someone in management) about this to get more time, might be time to start looking elsewhere for employment.

    If you’re not happy at work, chances are you won’t be happy in life.

  10. @Emran, I actually like your question. It shows the other aspect of the very same problem. On that question, I would say that I am motivated by good supportive words. In that regard my manager is indeed very helpful. I do get constructive criticism and he highlights my areas of improvement which is very helpful. I believe that good words amalgamated with a proper amount of direction does work. At least in my case it does. IMO that is the art of management and managers should be picky of their words and careful of their approach. I have seen people working harder if ample amount of motivation is given. In our company we have the practice of giving “Spot” awards which actually is meant for acknowledgment of the good work done by the individual and also motivate others. Many other enterprises have similar approaches. Team outings and recreational activities are also good ways to release the stress and get the team in action. Thanks for putting light on this aspect of the issue.

    @Michael, I totally agree with you. Being in a senior position not only gives you a responsibility to write good code which reflects your experience and maturity but it also gives you an opportunity to motivate your juniors. As I said, good coding is not just an effort but it is also a practice. If you deliberately delve into writing something stupid then that will actually hamper your own skills, credibility and respect in long run.

  11. A very good point. Currently I’m just like you and hope to keep the shape for a long time, but I’m afraid. B looking at the bad code deadlines overwork can break me really soon. Sadly :(
    Anyway I don’t want to leave, because I thing they will have hard time without me, so I decided that I will only leave if I get a great offer.

  12. Your point to some extent arguable like Tristan mentioned but you can not completely deny the fact that many coders (people who don’t know how to write good code), don’t have exposure to write good code and practices. To argue about code is bad, you must know whats good. Also it’s a common practice to criticize what his successor has developed.

    No body try to avenge the company but the company is alone responsible for the mess. They are not following review and refactoring process, what the project manager or team lead was doing when that guy is wring bad code, why nobody noticed that found out reasons behind it. Stress and tight schedule always leave their effects in long run. Management always forgets the long term consequences to gain short term profit.

    Keep in mind that “Quality is a management driven activity/process.”

  13. @Jawed, Indeed a very valid point. I had this question in my mind when I came to know about the reason for this unprofessional behavior. As you said, due to the short development time and to earn maximum benefits in immediate future, management tend to avoid standards. Due to tight schedule our team was not following peer review. I found this issue because I had to modify the aforementioned script.
    Having said that, It does not justify me or anybody for that matter, as an individual to deliberately compromise with the profession due to stress and pressure. In my knowledge, I will never write a bad code or design a bad algorithm which would be a pain to maintain. Generating Logic is a creative process. However, I agree that in many cases due to several factors at managerial or enterprise level, quality is compromised to certain extent. The case I mentioned does not fit in this criteria though as it deals with an individual.
    Finally, as others mentioned, if you are not happy in your job then talk about it to the manager or start looking elsewhere.

  14. [...] was reading an article about Reasons to write bad code !!, the author was sharing his experience about having problem with some bad code, written by his [...]

Leave a Reply

(required)

(required)