Member-only story
Cleaning Up Code 101: Learning from Uncle Bob’s ‘Clean Code’ Refactoring Examples (2)
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.
- Make it focus. move the variables closer to their usage.
- Early return.
- No nested if.
- Check duplicates. extract method.
- Minimalism. Only check once, and do it once.
- Try not to use comments to explain the code (but make the code self-explain)
- Break down statements into smaller functions. for clarity purposes. make the code intention as explicit as possible.
- The caller should be above Callee.
- 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)…