December 5, 2007

A NeoVictorian Response to YAGNI

A maxim of Agile Programming is that You Aren't Gonna Need It, abbreviated YAGNI.

Conventional designs and specs tend to be too general and too elaborate. You start out with a data structure to hold a couple of People. Someone suggests that it would be better to have a vector, so you could have more than two if you need to. Then someone else wants to put it in a mySQL database. And then we're gonna run it on a remote system, on rails. It's easy to add generality to a spec. It makes you look really smart, especially when someone else is going to do the coding. But too much generality too soon makes the code age prematurely; you can get old, brittle, confusing code that looks like it's yellowed with age, even though it's not even finished yet.

Much of the time, this generality won't turn out to be needed. Even if it is needed, building it later means that you defer the development and testing cost, and that saves money. In the past decade, as we came to understand refactoring better, we have become much more comfortable with deffering these costs.

In the NeoVictorian workshop, YAGNI is balanced by the opposing sentiment: Go Ahead, You're Entitled.

Also known as 'Go ahead, live a little!' It's what your aunt might tell your mom when she can't decide if she should have some apple tarte with crême anglaise and a cute little glass of spätlese, when mom thinks she really should go fold the laundry.

Sometimes, it's worth building the good generality early, because it will open new vistas and new opportunities. You might, for example, see a place where you could get by with a pair of Peoplee> but the code would be really elegant if you went right ahead and used a Composite. GAYE says, "if it's really cool, go ahead and invest now." It makes the code better, opens new vistas, new opportunities. It lets you try new things, because you've got a better, more general starting point for quick experiments.

If it doesn't work out, you can always refactor back to the simpler YAGNI plan.

What's the difference? The guy in the spec meeting is trying to look smart, or maybe just trying to look like he's paying attention and contributing to the team: the excess generality will be water for someone else to carry. The NeoVictorian is probably going to carry the water himself. It might be a little more work to carry that pail, but if it makes our part of the system better, that work is little to ask. Perhaps it will open new vistas, and perhaps it will let us build something else tomorrow, something that will matter.

Worst case, a little GAYEity might be an economic wash. On the one hand, if YAGNI applied then you've spent some development time building something you didn't need. But that time might have gone down the drain anyway, because the alienated coder with no opportunity to build a proud and soaring thing might take the afternoon browsing and brooding, or polishing her resume. Thou shalt not muzzle the ox when he treadeth out the corn, or fence the thoughts of your programmers when they're turning bits and rust to gold.