Member-only story

Cleaning Up Code 101: Learning from Uncle Bob’s ‘Clean Code’ Refactoring Examples (2)

LORY
6 min readApr 16, 2023

--

Let’s continue the code cleaning-up journey.

Beginning

In the last post. we have learned a few points from Bob’s code when we refactor a mess.

  1. Make it focus. move the variables closer to their usage.
  2. Early return.
  3. No nested if.
  4. Check duplicates. extract method.
  5. Minimalism. Only check once, and do it once.
  6. Try not to use comments to explain the code (but make the code self-explain)
  7. Break down statements into smaller functions. for clarity purposes. make the code intention as explicit as possible.
  8. The caller should be above Callee.
  9. Once done. scroll the class from the top down. you should feel like reading an article or newspaper.

Again, I’m not Bob’s friend(I wish I am) and I am not selling his book.

The purpose of these posts is only to help devs (also myself), If time permits, we clean our coding debts, and should never stop at “just make it work”, archive reliability and clarity should become a basic standard of our coding.

So let’s start another sample.

The original code

package literatePrimes;
public class PrintPrimes
{
public static void main(String[] args)…

--

--

LORY
LORY

Written by LORY

A channel which focusing on developer growth and self improvement

No responses yet