Scott on Writing

Musings on technical writing...

Tuesday, August 26, 2008 #

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 @ 9:55 AM | Feedback (1)

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<August 2008>
SMTWTFS
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

Comment Stats

DayTotal% of Total
Sunday 2046.9%
Monday 42314.3%
Tuesday 50116.9%
Wednesday 54518.4%
Thursday 57219.3%
Friday 53618.1%
Saturday 1856.2%
Total 2966100.0%

Hour1Total% of Total
12:00 AM 752.5%
1:00 AM 802.7%
2:00 AM 672.3%
3:00 AM 812.7%
4:00 AM 642.2%
5:00 AM 1234.1%
6:00 AM 1153.9%
7:00 AM 1755.9%
8:00 AM 1876.3%
9:00 AM 1565.3%
10:00 AM 1866.3%
11:00 AM 1926.5%
12:00 PM 1996.7%
1:00 PM 1846.2%
2:00 PM 1675.6%
3:00 PM 1344.5%
4:00 PM 1153.9%
5:00 PM 1063.6%
6:00 PM 993.3%
7:00 PM 1063.6%
8:00 PM 903.0%
9:00 PM 842.8%
10:00 PM 893.0%
11:00 PM 923.1%
Total 2966100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 4.91157
Monday 4.92379
Tuesday 4.21471
Wednesday 7.42668
Thursday 6.53666
Friday 5.17450
Saturday 4.73175
Total 5.522966

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 4.0048
8:00 AM 4.29133
9:00 AM 6.04290
10:00 AM 5.83274
11:00 AM 4.36192
12:00 PM 6.44348
1:00 PM 3.14132
2:00 PM 5.04227
3:00 PM 7.97303
4:00 PM 3.8199
5:00 PM 6.00168
6:00 PM 4.56114
7:00 PM 8.95188
8:00 PM 8.58163
9:00 PM 5.00115
10:00 PM 6.31101
11:00 PM 4.5732
Total 5.522966

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


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles