Specific And General Problem Solving

(Polya, I think, argues that it is sometimes easier to solve a more general problem than it is to solve a specific one -- BT)

A good example of solving a general problem for me is FunctorObject. It would have simplified a host of solutions I wrote in the last five years. However, I couldn't have imagined FunctorObject until I wrote all those less-good-solutions. I just can't do it. Maybe someone else is smart enough, but I'm not.

XP says to solve the most general problem you can imagine (DoTheSimplestThingThatCouldPossiblyWork). But don't halt progress just because you imagine there might be a general solution out there that you haven't discovered yet. Trust that when insight comes, your UnitTest's and PairProgramming and ReFactoring are up to the task of retrofitting the more general solution.

I watched my kids interact with Italian-speaking kids of the same age. Mine would just speak English; the Italian kids would speak Italian. After three days, my kids spoke a few words of Italian, and the Italian kids spoke a few words of English. If this continued for a few months, obviously everybody would've been able to speak both languages. But this all happened without charts or graphs or grammar rules.

This is analogous to the process I follow- get the behavior you want (as specified by UnitTest's), then discover the "right" structure for the logic you have.

I am experimenting with this right now. I am writing a stock trading simulation, PairProgramming with my 14-year-old daughter. Having just worked on a big unit-linked life insurance system, I "know exactly" how to design it. However, I am forcing myself to just take it a unit test at a time. The result is a surprise- simpler than I thought and different objects than I thought. And this is for a system I KNOW how to design. Imagine if I was developing something for the first time.

All that said (or rather, rambled), there is a place for solving a more general problem than you have. If I am completely stuck making piecemeal progress, then I ask the question "What object would I need in order to make this code simple?" But this is a last resort for me- first I take a walk, switch partners, read science fiction, or go home for the day.

--KentBeck


EditText of this page (last edited November 30, 2006) or FindPage with title or text search