1 Comment

Double Entry Programming

While working on a mock library for C (CMock), I began to think a tool should be made that would take as input a written test with all its mock calls and automatically generate actual code that would pass the test. I thought it seemed useless to basically rewrite in source what you just wrote in the test. I used to think that. But then I remembered something that made me see the value in this seeming duplicative work.

Accounting 101

Accounting 101 is a college class I really never should have taken. It was for an Information Systems degree rather than the Computer Science degree I got. But I actually enjoyed the class, and the main thing I remembered and was impressed by was double entry bookkeeping. Follow the link for info from wikipedia about it, or you can check out JBooks, a simple accounting system I wrote long ago, JBooks is a simple checkbook balancing program that uses a SQL database backed double entry system for managing your grocery receipts. (I once had too much time on my hands.)

Double Entry Programming

Now I see tests not as just an additional thing that verifies your code, but an actual piece of your code. Just like in accounting it is both the debit and credit entries that go together to make good bookkeeping. The test and the source verify each other. The writing of one corroborates the writing of the other. This idea also goes well with the old idea of throwing away the first version of code and rewriting it to do it better. Tests written using good mock libraries basically implement the ideas needed for the requirement being tested. Writing the actual code after that is your second chance and often does help find mistakes in understanding the requirement—improving both the test and the project.