Clean Code: Smells and Heuristics

This is a linkable reference of code smells & heuristics for better code reviews, inspired by the chapter of the same name in Bob Martin's "Clean Code".

For those who are interested, there is a brief history of the site and how it came to be.

Like many I was inspired to be a better software engineer after reading Clean Code and found myself wanting to reference certain smells & heuristics in code reviews rather than explaining them all the time.

So I asked Bob's permission on Twitter and he obliged!

Unfortunately some time later Bob realised I might need permission from his publisher and followed up with me, which was fair enough

Over the next few years I exchanged emails with the publisher (turns out we are very slow at replying to one another) and eventually they went silent so I decided we should just community-source our own smells & heuristics instead!

Comments

C1: Reiterating The Code

The best language for expressing what a program does is code. Comments that explain what the code does in a more human-friendly way are obsolete as the code can be refactored to be more readable, for example, by extracting well-named functions or variables. What’s worse, such comments are likely to become out of date next time the code changes at which point they become misinformation.

// Checks if x is divisible by y
x % y === 0;

isDivisibleBy(x, y);

function isDivisibleBy(x, y) {
  return x % y === 0;
}