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

LORY
5 min readApr 16, 2023

Read <<clean code>> again, refactored the samples, and compared them with Bob’s version, this is why my code sucks.

Bob said

Clean code is better than dirty code — uncle bob

Yes of course. we all agree that, we want our code clean, and always want to write clean code the FIRST time, when we see “dirty” (according to ourselves) we turn it into “clean”.

we thought once the mess was cleaned, happy team and better life.

However, reality is not like that.

  • The timeline is there.
  • Urgency happens.
  • We start to rush things.
  • It becomes someone else’s (ugly) legacy project who just joined this company.
  • What is the point to change what is already working?
  • We make it work, and stopped there.
  • It’s a loop.

In the end, cleaning up code becomes a lifelong task

In code review. I keep seeing some common mistakes keep coming again and again (including myself).

Here I want to share some thoughts with you by using Bob’s code sample. my code also sucks, but we can learn together.

Let’s start.

The original code

--

--

LORY
LORY

Written by LORY

A channel which focusing on developer growth and self improvement