YAGNI

Saturday 28 February 2004

A time-honored principle: You Aren’t Going to Need It. It basically says to only build things when you really need them. Too often engineers over-design, adding things to the code (or even the product) on the theory that eventually they will need them. And more often than not, You Aren’t Going to Need It.

I just removed the last vestiges of one of these ill-considered appendages. I had to touch 24 files to get rid of the empty maybe-we’ll-need-it-someday interface, all the places we handed one around, all the places we provided NULL for the argument, and all the places where we ignored the argument passed in.

Comments

[gravatar]
Bob 11:58 AM on 28 Feb 2004

You sometimes see a related notion in Windows API functions where there's some random argument that is not well defined in the documentation except that it's safe to pass a NULL. It's likely that the argument was for a feature that never got fully implemented and the argument is a vestage. More recently it seems that Microsoft is more consistent is using data structures as arguments and using the self-reference "sizeof(...)" as the first field as a type of version number for the structure rather than adding an "argument just in case we need it".

[gravatar]
andrew 4:44 PM on 28 Feb 2004

You'll need that interface tomorrow, don't lose that POD. I just got fininshed looking at an API that took a callback interface, everybody passed in a "this" pointer. The internal notification facility would fire up, iterate through the "interfaces" (all "this") and call laboriously call back on itself via COM. Pitiful.

[gravatar]
Christopher 3:05 AM on 29 Feb 2004

Sound advice, to be sure. But I've been known to spout off a few hard and fast rules myself ("Never return null!"), and the counterargument always comes down to experience and judgement. There are times when thinking ahead reaps big rewards. And it's important to note that YAGNI is not an argument for writing throw-away components. "Why do it right today, when it's just going to have to be re-written tomorrow?" is a self-fulfilling prophecy, and I've personally seen it trap half a department in a permanent maintenance cycle, too busy propping up "leaning towers" to produce anything new.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.