Excerpt from Code Complete: A Practical Handbook of Software Construction, Second Edition 2nd Edition

by Steve McConnell

Excerpt from Code Complete: A Practical Handbook of Software Construction, Second Edition 2nd Edition by Steve McConnell

The computer doesn’t care whether your code is readable. It’s better at reading binary machine instructions than it is at reading high-level-language statements. You write readable code because it helps other people to read your code. Readability has a positive effect on all these aspects of a program: 

  • Comprehensibility 
  • Reviewability 
  • Error rate 
  • Debugging 
  • Modifiability 
  • Development time—a consequence of all of the above 
  • External quality—a consequence of all of the above

Readable code doesn’t take any longer to write than confusing code does, at least not in the long run. It’s easier to be sure your code works if you can easily read what you wrote. That should be a sufficient reason to write readable code. But code is also read during reviews. It’s read when you or someone else fixes an error. It’s read when the code is modified. It’s read when someone tries to use part of your code in a similar program. 

Making code readable is not an optional part of the development process, and favoring write-time convenience over read-time convenience is a false economy. You should go to the effort of writing good code, which you can do once, rather than the effort of reading bad code, which you’d have to do again and again. 

“What if I’m just writing code for myself? Why should I make it readable?” Because a week or two from now you’re going to be working on another program and think, “Hey! I already wrote this class last week. I’ll just drop in my old tested, debugged code and save some time.” If the code isn’t readable, good luck! 

The idea of writing unreadable code because you’re the only person working on a project sets a dangerous precedent. Your mother used to say, “What if your face froze in that expression?” And your dad used to say, “You play how you practice.” Habits affect all your work; you can’t turn them on and off at will, so be sure that what you’re doing is something you want to become a habit. A professional programmer writes readable code, period.

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics