I have seen some programmers tweaking their code over and over again not only to make it 'work good', but also to make it 'look good'.

IMO, 'clean code' is actually a compliment indicating your code is elegant, perfectly understandable and maintainable. And the difference comes out when you have to choose between an aesthetically appealing code vs. code that's stressful to look at. 

So, how many of you actually write 'clean code'? Is it a good practice? What are the other benefits or drawbacks of this?

I would argue that many of us do not write clean code. And generally, that's not our job. Our job as software developers is to deliver a product that works, on time.

I am reminded of Joel Spolsky's blog post: The Duct Tape Programmer.

He quotes from Coders at Work:


  At the end of the day, ship the
  f*****g thing! It’s great to rewrite
  your code and make it cleaner and by
  the third time it’ll actually be
  pretty. But that’s not the
  point—you’re not here to write code;
  you’re here to ship products. - Jamie Zawinsky


I am also reminded of Robert Martin's blog response:


  So. Be smart. Be clean. Be simple.
  Ship! And keep a small roll of duct
  tape at the ready, and don’t be afraid
  to use it. - Uncle Bob


If the code,a developer writes happens to be clean AND work (is deliverable), so be it, good for everyone. But if a developer is tinkering around trying to make clean and readable code at the expense of being able to deliver it timely, then that's bad. Make it work, use duct tape, and ship it. You can refactor it later and make it super gorgeous and efficient.

Yes, it's good practice to write clean code, but never at the expense of being able to deliver. The benefit of delivering a duct-taped product on time far outweighs the benefits of clean code that was never finished and delivered.

A good chunk of code I've come across isn't clean. Some are downright ugly.  But they were all released and used in production. Some may say that it's unprofessional to write messy code. I disagree. The professional thing is to deliver code that works, whether it's clean or messy. The developer must do the best he/she can, given whatever time that was allocated before delivery. Then, go back to clean up-- that's professional. Hopefully, the code delivered isn't pure duct tape and is 'clean enough'.
