Metaphor

The biggest surprise for me in coding the money example was how different it came out this time. I have programmed money in production at least three times that I can think of. I have used it as an example in print another half-dozen times. I have programmed it live on stage (relax, it's not as exciting as it sounds) another fifteen times. I coded another three or four times preparing for writing (ripping out Part I and rewriting it based on early reviews). Then, while I was writing this, I thought of using expression as the metaphor and the design went in a completely different direction than before.

I really didn't expect the metaphor to be so powerful. A metaphor should just be a source of names, shouldn't it? Apparently not.

The metaphor that Ward Cunningham used for “several monies together with potentially different currencies” was a vector, like a mathematical vector where the coefficients were currencies instead of x2. I used MoneySum for a while, then MoneyBag (which is nice and physical), and finally Wallet (which is more common in most folks' experience). All of these metaphors imply that the collection of Moneys is flat. For example, "2 USD + 5 CHF + 3 USD" would result in "5 USD + 5 CHF". Two values with the same currency would be merged.

The expression metaphor freed me from a bunch of nasty issues about merging duplicated currencies. The code came out cleaner and clearer than I've ever seen it before. I'm concerned about the performance of expressions, but I'm happy to wait until I see some usage statistics before I start optimizing.

What if I got to rewrite everything I ever wrote 20 times? Would I keep finding insight and surprise every time? Is there some way to be more mindful as I program so I can squeeze all the insight out of the first three times? The first time?

The above quote is from Chapter 17: Money Retrospective of TDD by Example. I thought of taking only parts of it but I felt I would lose something. There is a movement in that passage to those final questions that reverberate in my mind. Is there a core metaphor to all systems that could unlock the design? If we think of the definition of metaphor as a compressed proportion, a statement of equality between two ratios. It's not just that something is like something but that it is something. It's a statement of equality. You can look at one and see the other.

It took Kent Beck 20 iterations of the same problem before he found the metaphor that unlocked the design. I can't remember anytime in the last 2 years were I had the chance to do a second iteration of the same problem.

I don't have much else to say other than I think I need to find a way to give myself more chances of discovering the right metaphor.