Quality is line one: 8 characteristics of good software code

When developers dish on what makes some source code particularly “good,” these qualities tend to get mentioned frequently.

Sign on a wall that says Quality Starts Here

Software code seems pretty ubiquitous these days, since software seemingly powers everything around us, from computers to cars to refrigerators. But not all code is created equally. Different software programs, even those that are meant to serve the same purpose, can differ greatly in the quality of their writing. What defines “good” software code? Developers will often have different answers to that question. However, a handful of qualities are often cited as being characteristic of well-written code. Here are 8 such characteristics and developer input, culled from various online discussion forums where the question “What makes good code?” was kicked around.

See also:

13 of the strangest places developers have written code

Keyboard for one: 9 of the most impressive solo programming efforts

Superbugs: 10 software bugs that took way too long to meet their maker

10 signs you’ve been coding too much for too long

Exposing the source: 16 pieces of classic software whose code is now accessible

Superclass: 14 of the world’s best living programmers

A hand giving a thumbs up in front of a sign that says Good Job

It works

Software, ultimately, is meant to serve a purpose. While some developers feel it goes without saying, others still feel it necessary to say that the first thing good code must do, simply, is work. If the code doesn’t fulfill the needs for which it was originally designed, then it cannot possibly be considered good.

Quotes: “... code that actually works is the first thing.” practicalpants

“The only metric that matters: there is a user, using the software.” fit2rule

“Beautiful readable, testable, maintainable code that fails to meet the business need is still a failure.” codingdave

Bookshelves at a library under a sign that says Easy Reading

It’s easy to read

Developers seem to agree that one of the most important qualities of code is its readability. Code that’s written in a way that makes it easy for other programmers to understand with a minimal amount of time and effort is considered top notch. Good naming, clear control flow, and smart smart use of comments all help to make reading code much less of a chore and, hence, easier to maintain, extend or reuse.

Quotes: “Great code is, above all, readable. The best code does not require comments to explain the small details, but only the large details of approach or nuance. When you read great code, you can easily follow the flow of control.” Gary Wisniewski

“The function and variables names sufficiently explain what is going on, the comments explain why the code is a certain way.” patrick

“The faster someone can look at it and understand it. The faster the application will move forward (feature and revenue).” Glennular

“There is really no good criteria other than how fast you can understand the code.” mojuba

A number of boxes with the word TEST on the side

It’s testable

Software developers generally agree that a requirement for code to be considered of high quality is that it can be tested. More specifically, good code should be testable programmatically. In other words, the code has been written in a such way that automated (unit) tests have been (or, at least, could be) created to ensure that each component of code does what it’s supposed to do.

Quotes: “Great code is always well-tested, and usually it is necessary develop tests (which are hopefully also great), which exercise every possible combination of conditions the code will encounter.” Gary Wisniewski

“I'd also look for testability... ” Jon Skeet

“Unit tests have many benefits and are usually a good sign of code quality” Ayman Hourieh

“Any indication that the developer treated the Unit Tests as code and applied some thought to their design rather than just churned out masses of ‘compiled scripts' would increase my optimism that the underlying code was good….” Modan

Mechanics working on a car rendered in LEGOs

It’s easy to maintain

No matter how well a piece of code is written, bugs will be found that will need to be fixed. The ease (or difficulty) with which that can be done will depend on things like its readability, modifiability, and simplicity. Whether the original developer or someone else will have to do this work, programmers agree that code which is easy to maintain is considered to be good code.

Quotes: “All code has to be maintained: no need to have that task made more difficult than necessary.” gbn

“I've seen code that was really ugly which nevertheless was easily maintainable, and I've seen pretty code that had to be thrown away and rewritten from scratch.” Kristopher Johnson

“What makes the difference between working code and great code is maintainability.” David Rachamim

Two women view Edvard Munch\'s painting "The Scream" at the Museum of Modern Art
REUTERS/Mike Segar

It’s pleasant to look at

While the look of source code isn’t related to how it actually performs, it can still matter to developers. The use of proper formatting such as spacing, indentation, and capitalization can make a software program easier (or, at least, more pleasant) to read and, hence, understand. Many programmers think that better looking code is higher quality code.

Quotes: “... in order to have good code, it is necessary for the code to be well formatted, obeying conventions and not a big incoherent mess.” Tom Hawtin - tackline

“The very first thing, before I even start reading the code would be code indentation.” Michał Piaskowski

“Code that looks beautiful is almost always of superior quality; logically it shouldn't be, but it is.” Keith Williams

A street sign that says Change Alley

It’s easy to change

The functionality of an existing piece of code will often need to changed, expanded or reused elsewhere in the future. Good code is often considered to be that which can be modified with a minimum amount of effort. Most importantly, developers like code that can be changed without causing unpleasant side effects.

Quotes: “You don't really know how good someone's code is until you try to change it.” Kristopher Johnson

“... great code makes it easy to extend, expand, or modify, and hard or impossible to break when doing so” Aaron Schlesinger

“You know you write good code when… The brand new guy/gal was just told to make modifications to a system you built 6 months ago and he/she never once asked you a question” Cape Cod Gunny

The words “Keep it simple stupid” embroidered

It’s simple

A piece of source code may ultimately be doing complex things, but the best code, developers often say, is often very simple. This means many things such as avoiding deeply nested loops, big if/else statements, and keeping methods, functions, and other blocks of code short and highly focused. The best code writers will know how to get the job done without over-complicating things.

Quotes: “... there's a proven statistical correlation between code complexity and bug counts….” Neville Kuyt

“... no blob classes or methods with an infinite number of purposes. Each layer of abstraction simple enough to keep in mind in its entirety.” mhomde

“Each function does exactly one thing.” Otávio Décio

“... perhaps the most important thing is keeping the code simple and to the point.” David Rachamim

Usain Bolt winning the men\'s 200m final at the London 2012 Olympic Games
REUTERS/Stefano Rellandin

It’s efficient

To some developers, the best code is code that runs fast and uses minimal system resources. Run time efficiency is considered especially important for software that’s meant to perform computationally intensive tasks, such as in scientific computing. Faster execution times can often come at the expense of code readability, a tradeoff that some developers are willing to make.

Quotes: “Great code has four characteristics: 2. It runs fast. “ Anthony Wang

“Speed isn't necessarily a primary indicator of good code, but good code shouldn't be unnecessarily slow or wasteful.” Caleb

“In general, I'd consider the fastest code the better code even though it's less readible.” Joris Meys