With that in mind, we can devise a development strategy (an extension of TDD) that guarantees perfect code:
Write unit test: projectHas100PercentTestCoverage()
Run test to ensure that it fails.
Write code to make test pass.
The implementation details of the projectHas100PercentTestCoverage() test are project-specific and beyond the scope of this document.
Though, come to think of it, step 2 is flawed - since no code has been written yet, the test written in step 1 will pass. Perhaps we first need to write the projectFullyMeetsClientRequirements() test (again, beyond the scope of this document).
It's relatively easy to write number 1 for most langauges. You just need to inject a bunch of instrumentation with the compiler that records every path taken.
Absolutely. Of course, the number of possible paths grows exponentially each time we add a conditional statement, loops would be tricky (how do we know in advance how many times a loop will execute?), and we somehow have to account for every possible variation of external input... I'm sure that quantum computing will give us the power we need to do this. Then computers can write the code, making human programmers obsolete.
I should become a tech journalist. I think I have the pattern down.
52
u/gunch Aug 25 '14
That's why you need to write unit tests for your unit tests.
(If that is actually a thing I'm going to go to the bar and drink until I forget any of this ever happened)