4 ms·
I'm not a great programmer, I can't usually write code that does exactly what I expect the first time, so I use unit tests with a debugger in my IDE to run smal
by jerkstate 8y ago
I'm not a great programmer, I can't usually write code that does exactly what I expect the first time, so I use unit tests with a debugger in my IDE to run small portions of my new code until it works the way I envisioned it before I started writing it.
This is a lot faster than my old method of writing code that doesn't quite work, and running the whole program over and over with small changes and print statements each time.
- matt2000 8y agoYes, that's pretty much where I've gotten to as well. Might as well put in the effort to move that process into unit tests as then you get to run it repeatedly for free from then on.
- TeMPOraL 8y ago> so I use unit tests with a debugger in my IDE to run small portions of my new code until it works the way I envisioned it before I started writing it. In languages like Lisp, this is what you use REPL for. It's an insanely more efficient way of working than the usual edit->recompile->run the whole app again. However, couple of years working with Common Lisp and (recently) Clojure taught me that, even with a good REPL at your disposal, properly testing code as you write it can get pretty unwieldy - especially if the inputs are complex/large. I found it beneficial to write unit tests and call them from REPL instead of testing the code in REPL directly, as it's easier to maintain and develop individual test cases, as well as re-test all of them when I alter the code I'm working on. (That's of course apart from the fact that unit tests are more permanent, and provide value later on.) TL;DR: thumbs up for writing unit tests even when working in an interactive programming environment.
- nradov 8y agoEven with Java now it's usually possible to modify a running application while you're debugging. Eclipse handles this pretty well.
- Sophistifunk 8y agoREPLs are a great tool for exploring your ideas, and poking your software to test it "right now" but once you're happy with a small piece of code, nothing beats a suite of unit tests to help you refactor with confidence as your implementation gets a bit too hairy and you need to rejigger it in order to progress in a direction you didn't see coming.
- jpitz 8y agoYou know, it's so much more vastly important to understand the expectation then it is to get the implementation correct the first time.