4 ms·
I feel like the bottom up style is possible in static languages like C++ too, except instead of manually testing small functions in the repl, you can write smal
by klipt 5y ago
I feel like the bottom up style is possible in static languages like C++ too, except instead of manually testing small functions in the repl, you can write small unit tests for them instead. In a way it's even better because a test written once can be run many times, while testing in the repl requires a manual test with every change.
- cerved 5y agoI'm guessing the draw is in the immediate feedback. Like iteratively creating a chain of commands in shell pipe. Compiling and then executing typically takes a minimum of a few seconds before you get feedback
- jlarocco 5y agoThat works in Lisp, too though, but it's easier and faster to run the tests in the REPL, so you get the best of both worlds. When I write Lisp I usually start testing in the REPL, iterate until the test code gets to be a few lines long, and then copy it over to the package's unit tests. Then I can keep iterating on both the test code and the code being tested. I'll do something like this in the REPL: (ql:quickload :mylibrary.test) (mylibrary.test:my-test-function) "mylibrary.test" will depend on "mylibrary", so quickload will load both packages when they've been changed, and I can re-run the test quickly using Alt-P to call up the previous REPL input. And the REPL is also really great for "what if" testing that you may not want to keep forever, like, "What happens if I call this function with an invalid parameter?" Hopefully there's a test for that, but it's often a lot faster to just call the function and see what happens rather than go dig through the test code and lose your focus.
- gumby 5y agoThis is how I develop in C++, though I am a Lisp programmer
- nwallin 5y agoconstexpr and static_assert make this a ton easier in C++. If your "unit tests" are static_asserts, the IDE will just highlight the broken parts. C++17 made this minimally useful, and things got spectacularly better with C++20 and constexpr vector/string. 23 is shaping up to move even more of the standard library to constexpr.
- klipt 5y agoI wonder if we'll end up with something like https://www.circle-lang.org/ https://www.circle-lang.org/ which lets you use pretty much the entire C++ runtime language at compile time. It certainly makes heavily templated code way more readable.