Commented-Out Code and Broken Windows

September 21st, 2008

I know that there are numerous blog posts already written about this topic, but I just can’t resist. I’ve just had it with commented-out code. Sure, everybody agrees that this is evil in it’s purest form, but why do I still have to endure so much commented-out code. It’s bad for my heart.

Don’t trust the source-control system? Get rid of it and replace is with a more reliable source-control system then. Check in more often! Feeling guilty about throwing away code? Too bad, go see a shrink or something. Keep your code clean at all times!

To me, a piece of code that contains commented-out lines is just another piece of crap. Most developers tend to just remove the commented-out lines and get on with it. I’m a bit more radical about this. I tend to throw away the whole shebang, like a tumor that needs to be removed along with it’s roots. That’s right. I remove all of the surrounding code as well.

Writing software is an act of discipline. Commented-out code is like a broken window. It introduces rot into a software system.

What triggered me to write this blog post besides the fact that I just can’t stand commented-out code and have to see so much of it? Well, I was reading the foreword of the book Clean Code which mentioned this again (and also chapter 4). Why does this need to be written down again and again (including this blog post, I know, I know)? It’s like periodically publishing articles in the newspapers that leaving dead bodies laying around is on the street is a bad thing. Isn’t this just common sense? Not in this industry.

Glad that I’ve got this from my chest. Again.

Jan, the relieved

Jan Van Ryswyck

  • http://elegantcode.com trasa

    1 to THIS. :)

  • http://davybrion.com/blog/2008/09/when-commented-out-code-is-acceptable/ The Inquisitive Coder – Davy Brion’s Blog » Blog Archive » When Commented-Out Code Is Acceptable

    [...] fellow Dutch ALT.NET member Jan Van Ryswyck wrote a post about how bad commented-out code is. I also truly hate it when i see code that is commented-out. It’s such a waste of time [...]

  • http://www.arjansworld.com/2008/09/22/linkblog-for-september-22-2008/ Arjan`s World » LINKBLOG for September 22, 2008

    [...] Commented-Out Code and Broken Windows – Jan van Ryswyk ‘ To me, a piece of code that contains commented-out lines is just another piece of crap ‘ I always feel like Ive done civilization a service when I remove old commented-out code from version-controlled source, so agreed here. Davy, on the other hand, has some situations where he leaves it, though [...]

  • http://blog.cwa.me.uk/2008/09/23/the-morning-brew-185/ Reflective Perspective – Chris Alcock » The Morning Brew #185

    [...] Commented-Out Code and Broken Windows – Jan Van Ryswyck talks about code quality, and that warning sign of commented out code. [...]

  • http://dotnetwitter.wordpress.com/2008/09/23/links-for-2008-09-23/ links for 2008-09-23 « Praveen’s Blog

    [...] Elegant Code » Commented-Out Code and Broken Windows (tags: tips) [...]

  • Brent

    Agreed. It’s a defect that doesn’t compile.

blog comments powered by Disqus