Techniques from <i>Code Complete, Second Edition</i>

Books about coding techniques rarely make it to the top of my reading list. Steve McConnell's original

Code Complete

(Microsoft Press, 1993), a book that presented the definitive set of code-construction guidelines, was a notable exception. However, the book's Pascal and C coding examples make it long and outdated. McConnell's follow-up,

Code Complete, Second Edition

(Microsoft Press, 2004), tackles modern-day code construction problems and provides all-new code examples written in C++, Visual Basic (VB), and Java. This book should be on every programmer's desk—read it and you'll write better code. Here are five code-writing concepts from

Code Complete, Second Edition

. You can find out more about the new edition at

Class Creation

Building classes is a common programming task that programmers frequently perform incorrectly. Classes, collections of methods that share a given responsibility, usually model real-world objects.

Code Complete, Second Edition

tells you how to build and use abstract data types (ADTs), build superior class interfaces, and use polymorphism and inheritance.

Building Routines

Building good code routines is a core topic of both editions of

Code Complete.

McConnell teaches you how to build code routines that reduce complexity, make programs easier to read, and avoid code repetition. You learn how to design loosely coupled, highly cohesive routines.

Naming Conventions

The way you name the objects that your programs use is the single biggest contributing factor to code readability. The book devotes an entire chapter to showing you how to write variable, class, and routine names that are readable, appropriate, and memorable.

Debugging Techniques

Debugging early in the development cycle can help you test code paths and find logic errors in your code. To help make your debugging more efficient, the new edition presents a scientific method for debugging. You'll learn how to form a hypothesis about an error's source, use testing to prove or disprove your hypothesis, then locate and stabilize the error.

Defensive Coding

Programmers often write code that assumes the data it works with is perfect. While the code might function as it's designed to under typical conditions, it can fail miserably when confronted with bad data or other unexpected conditions. Basically, coding defensively means that you design your code to handle incorrect input and to not pass along bad data. Defensive coding takes significantly more time, but a lack of defensive coding causes poor software quality.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.