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 logi…


This content originally appeared on DEV Community and was authored by Bruno Noriller

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


This content originally appeared on DEV Community and was authored by Bruno Noriller


Print Share Comment Cite Upload Translate Updates
APA

Bruno Noriller | Sciencx (2022-07-03T17:19:27+00:00) The pitfall of tutorials: no one codes like that. Retrieved from https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/

MLA
" » The pitfall of tutorials: no one codes like that." Bruno Noriller | Sciencx - Sunday July 3, 2022, https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/
HARVARD
Bruno Noriller | Sciencx Sunday July 3, 2022 » The pitfall of tutorials: no one codes like that., viewed ,<https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/>
VANCOUVER
Bruno Noriller | Sciencx - » The pitfall of tutorials: no one codes like that. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/
CHICAGO
" » The pitfall of tutorials: no one codes like that." Bruno Noriller | Sciencx - Accessed . https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/
IEEE
" » The pitfall of tutorials: no one codes like that." Bruno Noriller | Sciencx [Online]. Available: https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/. [Accessed: ]
rf:citation
» The pitfall of tutorials: no one codes like that | Bruno Noriller | Sciencx | https://www.scien.cx/2022/07/03/the-pitfall-of-tutorials-no-one-codes-like-that/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.