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
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?
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.
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!
If you’re learned about TDD then you know the 3 steps:
- Red: test don’t pass
- Green: make tests pass
Even if you don’t use tests, you can still make use of those three steps:
- It doesn’t work.
- It works.
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 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!
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.
Now… this is a story for another time.
In the meantime, search for: Kent Beck, Martin Fowler, Michael Feathers, Sandi Metz, and Uncle Bob.