This will be the first of many(I assume) posts on Computer Science and programming.
It wasn’t until I began taking classes that I first heard about test-first programming. Basically, the whole principal behind it is to make examples(and explicit tests) before you write the chunk of code you would like to write.
Why in the world would you do that?
Well, because it keeps your head on straight. It also makes sure that you have in fact written code to do what you originally meant it to do. What I have experienced is that if you wait until after you write that function/method/what have you to write tests, the tests you write will be based on the code you have just written. This means if you wrote code that doesn’t do what you want it to, you could write tests that test if the result is correct according to the code but not correct according to the code’s purpose.
That doesn’t happen in Test Driven Programming. Instead, having just gone through the logic for how to manipulate the input to produce the result, the code for the function will just flow from that. Then, you have working code and correct code.
Now, isn’t that useful?
I think so. Especially when you are working on a larger project where different components rely on several other parts, it really helps you think clearly. I’ve been using this principle for just about a year now and I’m definitely a much better programmer than when I started(couldn’t really have called me a programmer back then).
… more nerdiness to come!
- OMG, Test Driven Development Actually Works (jphpsf.com)