Shouldn’t be forgetting for one off scripts either, if that’s the logic you want to go with.
The tool exists, either you do it or you don’t and end up getting an error until the interpreter hits that line. It’s just the nature of being compiled at runtime.
TDD only works well if the problem is clearly specified before the first line of code has been written, which is rarely the case when I need Python for something.
So which is then? You want a one off script to just quickly crunch some numbers on a problem you still need to understand? Because that is where it is perfectly normal to get some errors and doodle around. That is the entire point of it.
Or you have a concise concept of what you are going to do, and how and why? Because that is what you do, when you program more than a “one off”.
Either you go to the store with a shopping list and you work through that list or you go browsing and see what comes up. But don’t expect to be as fast and have everything you needed, when you dont write your shopping list at home.
Often I use Python for exploratory purposes. Like, I got a bunch of data, and I want to know if a particular algorithm might work or not. I implement the algorithm, but realize the results don’t look good enough. So I tweak the algorithm, maybe even do major refactoring. Or maybe I realize my visualizations or metrics don’t capture what I need to see. Or maybe I must settle for some compromise?
I iterate on this repeatedly until I find something I’m happy about (or until I give up). Sometimes I end up with something completely different from my initial idea.
TDD won’t help me much here because the end result is unknown. For each iteration of this idea process I might even need to rewrite all the tests because none of them are valid anymore.
Then maybe use an editor with a decent linter and check the problems tab or just red line markers?? I also have those kind of runtime errors sometimes but I take the blame.
Mostly number crunching and data exploration tasks. Just so I can make informed decisions about the data I got. I do this rarely enough so it hasn’t been worth for me to install all these extra third party support wheels.
It doesn’t need to have large complex scopes. I have the brain of a goldfish. I program because it’s challenging. It’s challenging because I’m bad at it.
My brother. That’s why you do unit tests.
And lint
👆 definitely linting first 👆
finding errors as you type is even better than finding errors at compile time
But are you even a real programmer if you don’t test in production?
I shouldn’t need to do unit tests for quick one off scripts
Shouldn’t be forgetting for one off scripts either, if that’s the logic you want to go with.
The tool exists, either you do it or you don’t and end up getting an error until the interpreter hits that line. It’s just the nature of being compiled at runtime.
“Ohh, I got all these numbers I want to crunch using numpy or pandas and plot it using matplotlib. Hold on, I just need to write unit tests first.”
Well. Yeah. That’s test-driven development. It’s a very good practice.
TDD only works well if the problem is clearly specified before the first line of code has been written, which is rarely the case when I need Python for something.
So which is then? You want a one off script to just quickly crunch some numbers on a problem you still need to understand? Because that is where it is perfectly normal to get some errors and doodle around. That is the entire point of it.
Or you have a concise concept of what you are going to do, and how and why? Because that is what you do, when you program more than a “one off”.
Either you go to the store with a shopping list and you work through that list or you go browsing and see what comes up. But don’t expect to be as fast and have everything you needed, when you dont write your shopping list at home.
Often I use Python for exploratory purposes. Like, I got a bunch of data, and I want to know if a particular algorithm might work or not. I implement the algorithm, but realize the results don’t look good enough. So I tweak the algorithm, maybe even do major refactoring. Or maybe I realize my visualizations or metrics don’t capture what I need to see. Or maybe I must settle for some compromise?
I iterate on this repeatedly until I find something I’m happy about (or until I give up). Sometimes I end up with something completely different from my initial idea.
TDD won’t help me much here because the end result is unknown. For each iteration of this idea process I might even need to rewrite all the tests because none of them are valid anymore.
in this process it is just normal to get runtime errors. Your expectation is too high imo.
TDD is not appropriate for everything or everyone
Then maybe use an editor with a decent linter and check the problems tab or just red line markers?? I also have those kind of runtime errors sometimes but I take the blame.
What kind of quick one off scripts have large complex scopes where variable renames are difficult to track?
Besides, these days Python has great LSPs and typing features that can even surpass the traditional typed langs
Mostly number crunching and data exploration tasks. Just so I can make informed decisions about the data I got. I do this rarely enough so it hasn’t been worth for me to install all these extra third party support wheels.
Those support wheels are for your own (and apparently systematic) errors…
It doesn’t need to have large complex scopes. I have the brain of a goldfish. I program because it’s challenging. It’s challenging because I’m bad at it.
What’s that?
/s