TDLR: Refactor, refactor, refactor!
So, you want to learn some new language or framework, you find a tutorial and it takes you step by step.
First you start at A
then, of course, B
to the βlogicalβ jump to C
to finish with D
.
All elegant and logical, one point to another with all the steps you didnβt even consider you would need, done by the time you need then.
Just like when you actually have to do something right?
Programming is βdirtyβ work
In the short time they have to get you to watch the tutorial, they have to be neat and to the point.
But donβt kid yourself. Thatβs just the finished version after countless rounds of refactoring.
Even the best programmers out there first make a mess only to refactor and give you the neat version.
The pitfall of not refactoring
People who only go by the tutorial and think that IS programming end up thinking that, they too, just like the tutorial can make those complex jumps in logic and that their βfinishedβ product is as easy as A -> B -> C -> D
except itβs far from the truth.
They do something like: A -> Z -> J -> G -> Z -> C -> P -> O -> D
repeating some steps, making a roundabout way instead of a neat alternative, finish and call it a day!
TDD
If youβre learned about TDD then you know the 3 steps:
- Red: test donβt pass
- Green: make tests pass
- Refactor!
Even if you donβt use tests, you can still make use of those three steps:
- It doesnβt work.
- It works.
- Refactor!
Refactoring is like βwashing your handsβ
Uncle Bob says that making tests and refactoring are some things that are like washing your hands if youβre a surgeon. You donβt need to put it on the calendar, or maybe block a whole week of the month just for that.
Itβs something that you just do! Itβs expected to be part of any estimate you have.
Itβs something you simply cannot afford not to do.
The βboy scout ruleβ
The best time to refactor was when you made the mess, the next best time is now!
Every time you change something in the code is an opportunity to improve it.
So⦠every time you check out a file: refactor it!
Refactor, Refactor, Refactor!
Itβs never gonna be enough, and thatβs ok!
Every time you see the code youβve made and what you could do now will show your progress.
How to start?
Now⦠this is a story for another time.
In the meantime, search for: Kent Beck, Martin Fowler, Michael Feathers, Sandi Metz, and Uncle Bob.
Cover Photo by Markus Winkler on Unsplash
Top comments (0)