DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for The pitfall of tutorials: no one codes like that
Bruno Noriller
Bruno Noriller

Posted on • Originally published at linkedin.com

The pitfall of tutorials: no one codes like that

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)

Layoffs: It’s Okay to Not Be Okay