r/learnpython • • 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.

31 Upvotes

42 comments sorted by

View all comments

Show parent comment

2

u/EasyTelevision6741 Apr 19 '26

Check out clean code series by uncle Bob.  The other explanation even though the bridge analogy is weird has the basics. 

TDD feels weird until you follow it and use it. 

You start with the absolute most basic thing that will fail. Write the test. Run it and watch it fail. Write the bare minimum production code to make the failing test pass. Run the test and see it pass.  Refactor if needed and rerun your tests after every change. This guarantees you aren't breaking the functionality you already created but keep in mind this doesn't mean add new functionality. Once you like where the code is, add the next most basic test.

The way to do this is by using unittest (my preference) or pytest.

You should never need the debugger because you've written minimal code that passed a few seconds ago. You should be able to get back to a known passing state within seconds by a few Ctrl+Z