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

LORY
12 min readApr 16, 2023

This time is a bigger sample.

Beginning

In previous posts, we went through 2 sample codes and found clean code has the below attributes.

  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.
  10. Spend time on names.
  11. Simplicity does not always mean the number of lines. sometimes a smaller function could be turned into a class for better readability.
  12. “half refactored” code is a waste of time.

So you may ask, “What about abstraction”? and “dependency injection”?

Here it is. and let me show you how I did it wrongly (so you don’t have to)

The original code

public class Args {
private String schema…

--

--

LORY

A channel which focusing on developer growth and self improvement