If only I used Test Driven Development.
In TDD you first write the test, but just enough to have it fail.
After that you go to your class and write a small piece of code, just enough to have your tests pass.
You repeat until the user story is finished.
It’s not easy, because you will be slower on the short term.
It takes a lot of discipline.
I will confess I am still struggling with maintaining such a level of discipline.
But on the mid and long term it’s the best way to write code and saves you from a lot of headaches.
This meme is part of the “Test Pyramid and Test Driven Development” episode from the Clean Code course.