TDD
Adopt
https://en.wikipedia.org/wiki/Test-driven_development means writing tests before writing code.
The idea is to create a test which is what you want your code to output, then write the code to pass the test. An improvement on this idea is to add a third step, refactor, to the process resulting in a red-green-refactor cycle of development.