Clean code is code that a developer other than its author can read, change and extend without fear. The idea was made popular by Robert C. Martin in his book Clean Code.
This post shows ten clean code rules with real Java examples, each one a before taken from production code and an after you can copy. You will learn how to:
choose names that make comments unnecessary;
split functions so each one does one thing;
replace hard-coded values without waiting for a big project;
cut long argument lists down to one object;
make a block of code read like a story.
At the end there is a code review checklist with one line per rule.
1. Use intention-revealing names
A name should tell the reader why a variable, function or class exists, what it does and how it is used.…