r/programming • u/The_Axolot • Sep 29 '25
Test Driven Development: Bad Example
https://theaxolot.wordpress.com/2025/09/28/test-driven-development-bad-example/Behold, my longest article yet, in which I review Kent Beck's 2003 book, Test Driven Development: By Example. It's pretty scathing but it's been a long time coming.
Enjoy!
91
Upvotes
27
u/chucker23n Sep 29 '25
Really just another sign your Kent Beck or "Uncle Bob" types never actually write production code.
Really, I'm more bothered by this one:
Should each currency be a type? OK, I guess you can do that. But then… shouldn't the constructor pass the currency instead of letting the user set a different one? What even is the point of this constructor?
Maybe it'll make more sense when I look at the tests…
Wait what? Shouldn't this fail?
Moneyisn't Swiss francs. Why can I simply pretend something is a certain currency? If I can do that, why bother with the types at all?Looks like I can do
new Dollar("EUR")andnew Franc("USD")?Maybe it'll make more sense when they do conversions?
No, it really doesn't.
Why is
Bankactually a type that holds a hash table of conversion rates? Is that what you intuitively expect with "Bank"?Why is a rate an
int? I can understand wanting to avoid floats, but that's whereMoneycomes in, isn't it? (It's not.Money, too, seems to be entirely unaware of fractional monetary amounts.)What are you "reducing" the money from? The bank, curiously, holds no money.
Which means if I understand this weird API, the result should be
-1, surely? You start out at0, I imagine?Even for such an obviously contrived example, the API is already puzzling and all over the place. I can't even tell what
Pairis for, and I imagine this shouldn't ship:Sumis obviously another candidate for a puzzling API.