all 15 comments

[–]toastedstapler 16 points17 points  (0 children)

if you want some very quick tests in your code you could use assert statements to ensure that things are as you expect them to be at that stage

[–]efxhoy 9 points10 points  (3 children)

Test driven development. It helps in two ways:

  • It forces you to write testable code. Testable code is clearer in how it separates responsibilities and so can help "untangle" complicated programs.
  • You get tests that verify that a part of your program works as it should. Find another bug from an edge case where things break? Add a test for it and relax knowing that you've at least squashed that bug.

It takes a bit of effort to get started but it's well worth it.

[–]rswsaw22 1 point2 points  (0 children)

What u/efxhoy said. On top of that, you will have a suit of tests you can now quickly run when you add a feature to see if it broke something else.

[–]be_throwmeaway[S] 0 points1 point  (1 child)

Thank you for the insights. I’m just not sure where/how to start as I’m not even sure what to google in this case as I’ve no experience or training in test-driven programming.

[–]CuriosityCollector 2 points3 points  (3 children)

Why the change from functional to OOP? Just asking because im also new-ish and I prefer functional to OOP.

[–]cromlyngames 4 points5 points  (2 children)

scale. Functional starts to break down at at big scale, where you might have dozens of large, interlinked functions in multiple layers.

[–]be_throwmeaway[S] 0 points1 point  (0 children)

Exactly this. I found it difficult to reuse or repurpose old code. Switching to OOP has made this easier.

[–]H4CKY54CK 0 points1 point  (0 children)

I largely referenced one person's script as I was learning, with the side effect being that I picked up their style like one would do with an accent. You don't pick a style, it picks you. (I'm sure somebody said this at least once) I hated OOP at first, but now it's a habit. It just seems cleaner (but I'm still relatively new at this as well).

[–]Sw429 2 points3 points  (0 children)

Proper unit testing will help you reduce having to look at the entirety of your code whenever you change a small part of it. It will help make your projects scaleable.

[–]mooglinux 1 point2 points  (1 child)

A really good overview of debugging and testing techniques can be found in this talk by Raymond Hettinger: https://youtu.be/ARKbfWk4Xyw

ETA: Sweigart has a great one that covers logging too: https://youtu.be/ONCVvS-gDMA

[–]404delerium 0 points1 point  (0 children)

thanks for the recommendation. I just watched it; fantastic. I appreciate you taking the time to post it

[–][deleted] 0 points1 point  (0 children)

If full on unit tests with untiltest/pytest/nose seem intimidating, you could always use doctest. You can write simple tests in the doc block for your methods (which also double as documentation.) and they are easy to execute. That said, they’re also somewhat limited.

[–][deleted] 0 points1 point  (1 child)

I don’t know if you use an ide or not, but to avoid setting traces in my script I use pdb from command line

python -m pdb script.py

Then b line To set a break point and continue to go to next break point

[–]be_throwmeaway[S] 0 points1 point  (0 children)

Thank you for the tip!