4 ms·
Going back to Bentley, the point was not to code without testing but whether you could think through a small piece of code <i>before</i> testing. raganwald say
by FutureNerd 17y ago
Going back to Bentley, the point was not to code without testing but whether you could think through a small piece of code <i>before</i> testing.
raganwald says, "It feels very retrograde to try to write the whole thing out and only then start thinking about [...] edge cases." Nobody said you had to write it before thinking about edge cases! The idea is to think about the edge cases and incorporate that thinking into the code before you actually test the code--whether you can be--actually whether you know the steps to be--that thorough in your head.
One way to think about edge cases, of course, is to write the test code before the function. But after writing the tests, try writing the function correctly before testing it.
Of course, one of the potential bugs in binary search doesn't occur to people before they write and then try it. And, that bug is hard to test for, ahem, don't want to explain why.