Write code that humans can easily understand

Also known as

Beautiful code is simple code that humans can understand easily.

Motivation

We want to keep our systems maintainable over time, with clean, simple, testable code, keeping the speed of development high throughout the lifetime of the system.

You'll only get good code if you actually care about good code.

Applicability

Any time you touch a piece of code you strive to leave it better than you found it (either better structured, better tested, more understandable...).

Application

Find some open source code written by some well known acknowledged experts and see how the code is written. Compare it with the way you write code.

Start reading some of your oldest code and work. Reading your own old code can also be an enlightening experience. You will probably find that it is not at all as easy to read as when you wrote it. Look at how you have developed your skills over the years — it can be truly motivating. Observe what areas of the code are hard to read, and consider whether you are still writing code in the same way today.

For the person trying to understand your code, well written test cases are of great help. Hence pay great attention to the readability of the test that you write for your code. Test cases should report errors in helpful and meaningful way.

Write code as if you had to support it for the rest of your life. If you keep this point in mind, you would gradually improve towards becoming an expert programmer.

Consequences

Writing a simple readable code forces you to think straight in terms of overall design and the flow of the code.

People will form opinions about you based on the code that they see. If those opinions are constantly negative, you will get less from your career than you hoped. Take care of your career, of your clients, and of your users with every line of code.

The overall speed of the development of the project gradually increases if everyone starts caring about the code.

References

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

  • Martin Fowler, Refactoring: Improving the Design of Existing Code by Martin Fowler, Kent Beck (Contributor), John Brant (Contributor), William Opdyke, don Roberts, ISBN: 0201485672

Beauty of style and harmony and grace and good rhythm depends on simplicity. — Plato

Implementation Patterns by Kent Beck

The Xebia Essentials Cards

This page is part of the Xebia Essentials, a pack of flash cards about Software Development Done Right. You can get your own deck of Essentials cards in the Xebia store (sold out).

Buy Now