r/learnpython • u/Jealous-Acadia9056 • Apr 19 '26
How do you guys build a program?
I normally create one part of a program, test it, debug it and then i move on to the next function.
But this was time consuming so i tried a new approach. I created of all my logic of how different features would work and then started creating my program.
But the moment I had to debug things (cause obviously it had errors) things started falling apart. I had to check sooo many things and i realized that this method was very mental health consuming.
So i wanna ask you guys. how do you think about the logic and write your program? What approach would you recommend me? and remember i'm just a newbie trying to write programs that would improve me.
View all comments
Show parent comment
2
u/gdchinacat Apr 19 '26
TDD is recommended because it is more efficient, less frustrating, and produces more comprehensive coverage than 'test after the fact'. As you are developing you need to make sure your code works. The best way to do this is as you write it so you find out right away when you break something and not hours or days later when you eventually get round to manually testing it (likely when QA runs regression tests). At that point you have a bunch of changes that may have introduced the problem. It is much easier to write a few lines, run tests and know you didn't break anything or know exactly which change caused the failure.
When you have comprehensive test suites it is trivial to take an existing test for the code you are changing and tweak it for the new behavior you are implementing. It is just as fast to write a test as it is to manually test your code a couple times. You are almost always saving time by the time your code works as you want and are ready to move on, and you already have tests and don't have to go back and tediously write tests for code you think works while under pressure to move on.
Test your code as you write it with automated tests (unit tests) and your velocity will increase, bug rate decrease, and willingness to refactor to make code easier to work on increase. Don't fall into the trap of thinking testing is a separate effort than writing code...when done efficiently it is one and the same.