What is "good code"?

I was asked today to describe "good code".  Here is my response to that question:

How do you define “good code”?

“Good code” is code that functions. “Good code” is code that does what it’s supposed to do. After all, with so many applications in production, can most of that code be below average or “bad code”? However I am not interested in writing “good code”. I am interested in writing great code. I like writing code that does what it’s supposed to do and reads like it’s supposed to read. Great code does not make the reader ask “WTF?!” when reading it. Great code is code that all programmers aspire to write in their careers but only a persistent few ever do.

Great code is based on the concepts that universities teach but professors fail to teach you how. Great code is code that is loosely coupled, highly cohesive, highly readable and as a result highly maintainable. Great code is that which is appreciated more by the developer that maintains it, than the one who created it. The skill of writing great code does not come from talent, intelligence or experience but rather from practice with a deliberate attempt to learn how to write it.

Great code is not plagued by duplication. Great code is efficient. Great code is open for extension. Great code has clear separation of concerns. Great code has clear names for functions, class names and variables. Great code has small classes and small functions (methods). Great code avoids magic numbers. Great code is pronounceable. Great code has classes and methods that do one thing and do it well. Great code is so expressive that comments are rarely necessary to explain it. Great code utilizes design patterns to solve re-ocurring problems. Great code reveals the domain.

Great code is clean. Great code is concise. Great code is testable and tested. Great code is easily recognized by all developers and sometimes even referred to as “sexy” by the committed developers. Great code makes a programmer proud and not shameful.

I can go on and on about what “great code” is, after all code is my passion, but the one thing that I would like to point out is that great code is studied, researched and practiced by all those who care about code and I happen to be one of those aspiring craftsmen.

Also I cannot say all of this without giving credit to all of those masters of great code that have shared their knowledge of great code through teachings, seminars, articles, books, podcasts,user groups, etc. I am referring to the Martin Fowlers, Michael Feathers, Robert Martins, Steve McConnells, Eric Evans, Jeremy Millers, Jeffrey Palermos, Derick Bailey’s of the world. The list of great contributors is almost as long as the list of attributes of great code, so I will not attempt to name them all. Instead I just want to say thanks for their inspiration of writing great code.


AJ said…
Fernando although I am not a programmer I can appreciate your passion for your craft. Hopefully this passion becomes infectious and permeates throughout our organization.
Derek Greer said…
Great post Fernando! Keep 'em coming.

Popular posts from this blog

Simple Example of Using Pipes with C#