Scott on Writing

Musings on technical writing...

Speculative Development and YAGNI

It's amazing how much time speculative development can swallow up during the course of a project. Speculative development happens when a developer implements features above and beyond the requirements based on the assumption that he'll need such functionality at a later point in time. I think it's a trap every developer has fallen into at one point or another. We are tasked with something simple - like exposing the latest news through an RSS feed - and turn it into something complex - like building an entire RSS generation framework that can syndicate any data source.

In The Productive Programmer Neal Ford explains why software projects - as opposed to other engineering projects - are so prone to speculative development:

Usually, in the physical world, things tend toward simplicity unless you add energy to disrupt it. Software is the opposite: because it is so easy to create, it tends toward complexity (in other words, it takes the same physical effort to create both complex and simple software). It can take great effort to pull software back toward simplicity.

In other words, it's expensive in time and cost to increase the complexity of a bridge or car or house, which is why you don't see needless complexity added to such systems. But for software, it may only  take a few more hours to add some extra functionality that, while not required now, may be useful down the road. Another factor that leads to a high occurrence of speculative work in software projects is the typical mindset of a programmer. We like order and rigidity and building black boxes that can be plugged in elsewhere and used again. We enjoy challenges and solving problems. Spitting out the latest news in a simple RSS feed is easy, boring even. It's much more mentally stimulating to craft an RSS generation framework. (This predilection of self-directed framework building also helps explain why developers working on existing projects oftentimes advocate pitching the existing code base and rewriting the application from scratch rather than build on top of the work that's already been done.)

The main problem with speculative development is that it adds potentially unneeded code to the project, bloating its size, increasing the surface area of the project, and contributing to the code that must be tested. It's also potentially wasted time. Of course, speculative development isn't a problem if the speculative work is actually needed and used at some future point in time. But because there's no way to definitively say that the speculative work will eventually be needed (or that it will be needed but in some alternate form), it's best to build only what is needed in the here and now.

There's an acronym to keep in mind to help temper speculative development - YAGNI, which stands for "You Ain't Gonna Need It." Ron Jeffries, one of the founders of Extreme Programming methodology, summarizes the idea behind YAGNI succinctly:

Often you will be building some class and you’ll hear yourself saying "We’re going to need...". Resist that impulse, every time. Always implement things when you actually need them, never when you just foresee that you need them. ... You’re thinking about what the class might be, rather than what it must be. You were on a mission when you started building that class. Keep on that mission rather than let yourself be distracted for even a moment. Your time is precious. You might not need it after all. If that happens, the time you spend implementing the method will be wasted; the time everyone else spends reading it will be wasted; the space it takes up will be wasted. ... The best way to implement code quickly is to implement less of it. The best way to have fewer bugs is to implement less code.

Wise words from a wise man.

posted on Tuesday, August 26, 2008 9:55 AM

Feedback

# re: Speculative Development and YAGNI 8/26/2008 1:47 PM Andrei Rinea

Good advice! I feel it somehow relates to a blog post I've read recently : "The best code is no code at all" (Jeff Atwood / CodingHorror.com)

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<March 2010>
SMTWTFS
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Comment Stats

DayTotal% of Total
Sunday 2056.8%
Monday 42514.1%
Tuesday 51917.2%
Wednesday 55618.4%
Thursday 58019.2%
Friday 54718.1%
Saturday 1886.2%
Total 3020100.0%

Hour1Total% of Total
12:00 AM 782.6%
1:00 AM 812.7%
2:00 AM 682.3%
3:00 AM 822.7%
4:00 AM 692.3%
5:00 AM 1264.2%
6:00 AM 1193.9%
7:00 AM 1816.0%
8:00 AM 1926.4%
9:00 AM 1585.2%
10:00 AM 1886.2%
11:00 AM 1936.4%
12:00 PM 2016.7%
1:00 PM 1846.1%
2:00 PM 1695.6%
3:00 PM 1354.5%
4:00 PM 1153.8%
5:00 PM 1073.5%
6:00 PM 1013.3%
7:00 PM 1073.5%
8:00 PM 923.0%
9:00 PM 882.9%
10:00 PM 913.0%
11:00 PM 953.1%
Total 3020100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.00160
Monday 4.80384
Tuesday 4.04477
Wednesday 7.39680
Thursday 6.26676
Friday 5.07466
Saturday 4.78177
Total 5.403020

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 3.8550
8:00 AM 3.72134
9:00 AM 6.06297
10:00 AM 5.63276
11:00 AM 4.22194
12:00 PM 6.16351
1:00 PM 3.09133
2:00 PM 4.89230
3:00 PM 7.67322
4:00 PM 4.00108
5:00 PM 6.07170
6:00 PM 4.64116
7:00 PM 8.95188
8:00 PM 8.63164
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.403020

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles