cumulativehypotheses

mostly professional blather

On TDD and Double Entry Bookkeeping

leave a comment »

“Uncle” Bob Martin offers here a number of claimed parallels between TDD and Double-entry Bookkeeping (DeB). I think he’s rather missed important aspects of—surprisingly—both of those things. They aren’t primarily about correctness, although they do help with that, they are both more about knowing the state of your world.

That TDD is somehow like DeB is not an especially new observation, people have been making that comparison for a decade or more, but in the recent post Bob says that:

  • Both [TDD and DeB] are disciplines used by experts who carefully manipulate complex documents full of arcane symbols that must, under pain of terrible consequences, be absolutely correct in both type and position.
  • Both involve representing a long sequence of granular gestures in two different forms on two different documents.
  • Both techniques update their documents one granular gesture at a time, and each such update concludes with a check to be sure that the two documents remain in balance with each other.

This is…highly questionable. Bob uses the parallel to try to make programmers who don’t TDD with much enthusiasm (or even at all) feel bad, asking:

[…] why are accountants able to maintain their discipline so assiduously and so completely? Can you imagine a group of accountants saying to each other: “Guys, we’re really under the gun. We’ve got to finish these accounts by Friday. So, do all the Assets and Equities. We’ll come back and do the Liabilities later.”

No. You can’t imagine that. Or, at least, you shouldn’t. Accountants can go to jail for doing things like that.

With a suitable analogy to sloppy programmers. Also…highly questionable.

Suppose that your business chooses to use DeB, then…oh, but wait, that is a choice. DeB is not required of all businesses.

There are two gold-standard benchmark type things for financial reporting: GAAP (from the USA) and IFRS (rest of the world, ie most of it). The main point of these standards is to have common approach to reporting between businesses, to allow for comparisons, and a clear and accurate approach to accounting within a business; thereby to afford good management and avoid fraud. These standards relate largely to how the business is described in its published financial records. They do not, so far as I know, explicitly mandate DeB. However, for a business that’s much more than a lone sole trader it is hard to meet the requirements for financial reporting any other way. Not that a small scale Sole Trader would be reporting much, anyway, but that’s another story. I can be done, there is such a thing as Single Entry Bookkeeping and it is perfectly respectable, but its hard to extract from such records the kind of reporting that auditors, and even more so again markets, if your business is publicly traded, want to see. And that’s the important bit. Both GAAP and IFRS relate to what, and how, a business publishes about its finances.

People tend to view accountancy as a rather arid discipline, and tend to get hung up on the vast quantities of arithmetic required. But this is to miss the point. The accounts of a firm are just that: they give an account of what went on during a trading period. They tell a story. These invoices were settled, this capital expenditure was incurred, that provision for whatever it it was was made, and so on. The accounts tell the story of where the value of the company came from. The art of accountancy, and where it starts to overlap with management and finance, is how that story is told.

  • Do bookkeepers and accountants make mistakes? Yes. Do they go to jail for them? No. If they aid and abet deliberate fraud by the company, then they may do, of course. And if they get a reputation for making lots of errors then they will find it hard to secure work, and may eventually lose professional accreditations. But jail for honest mistakes? No.
  • Are a company’s accounts free of error at all times? No. At the close of an accounting period the accountant will prepare a “Trial Balance”, which is exactly what is sounds like—a first attempt at constructing a valid balance sheet. A balance sheet shows a net position for each account at the end of the period, taking all the transactions during that period into account. Is the trial balance bound to be correct because of DeB? No. There can be errors that do not break the accounting identity. Does anyone go to jail if the Trial Balance does not…balance? No. They just have to do a lot more work and hunt down the error. And recall that it is the Directors of a business that sign off and publish the financial reports of a business, not the accountants. And recall that in most jurisdictions you need two accountants: the every-day ones that help operate the business and the independent auditors who validate that this was done correctly. But it is still the Directors who sign off and publish the accounts.

Bob emphasises that DeB contains some built-in checks against error, he emphasises correctness. And at one level, DeB does help with correctness. If the fundamental accounting equation (the invariant: assets = liabilities + equity) is broken then an error has occurred somewhere. It could be a simple arithmetic error, and back in the day that was a very useful thing to be able to spot, or it could be a data entry error, and again, good to be able to spot that. But since the 1950s, starting with larger and extending now down to all but the very smallest companies, the arithmetic is fully automated and the data capture of receivables and payables and what-not is very largely so and the kinds of error that DeB flags all by itself are now very rare. The mistakes that DeB doesn’t catch are modelling errors.

A large business may maintain many, many accounts for different purposes. The “Double” in DeB can be misleading. A transaction is not necessarily recorded in in two accounts, but in at least two. Suppose that Consolidated Amalgamated wants to buy a new Turbo-Encabulator—those are pricey, so in addition to the (perfectly respectable) slight-of-hand in depreciating that capital expenditure they also sell a bond to raise additional cash. As a result of that one transaction a bunch of accounts will be updated: cash on hand, debt, perhaps a couple of kinds of short and long term asset, maybe others depending on how tricky sophisticated they want to be. Here are many opportunities for putting the wrong values in the “wrong”—that is, badly disadvantageous—places, even if the whole thing still balances out. Other kinds of check are required over and above the balancing.

DeB is more complicated than single entry and does need trained operators. If the correctness guarantees offered by DeB are relatively weak, why do it? One answer, and a very important one, is that with DeB the value of a company can be known exactly at any time. The invariant assets = liabilities + equity is true, in principle, all the time. Which means that the managers of a company, and its shareholders (if it has them) or other investors, can see the state of the company all the time. And, even better, can quickly assess the effect of a management decision or action on the finances of the company.

TDD does the equivalent for a codebase. It lets you find out its status at any time, and assess very quickly the impact of a change.

If TDD is like DeB, then we can ask: in TDD, who is it that fill roles comparable to those the auditors and the Directors? What is the equivalent of signing off the audited accounts?

Advertisements

Written by keithb

December 21, 2017 at 10:54 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: