Thursday, February 14, 2008

YAGNI

"You Aren't Gonna Need It."

We don't use this term much in our offices, but maybe we should.

YAGNI comes from the Agile / Extreme Programming (XP) development mindset. The idea is that for every feature request or "cool idea" that you or your manager or your customer might come up with, you ask yourself:
  • Do I really really need this now?
  • If you're sure you really really need this right now, then do it.
  • If you're considering it because you think there's a chance you might need it later, don't do it!
Sounds simple, right? Don't build code that you don't need right now. Or more accurately -- don't build code that does not serve to satisfy your customer's need right now.

But how often are we tempted to add in "cool ideas" to our models and projects? Or how often do we come up with a super-abstract "generic" version of something that we might need one day for another scenario?

Perhaps we add in a lot of output statistics to our model that we may think somebody will be interested in seeing one day. Or we quest for the ultimate generic reusable flexible abstract module for X (sorters, process flow, trains moving, etc. etc. etc.) that we know we're going to need for some future project that we may sell someday.

That's what YAGNI is for. It trains you to resist this temptation. Focus on the code that you need right now. Focus on the deliverable that you promised to your customer right now. Everything else can likely be put off until a later milestone - if at all.

Do you really really need this now?

Originally this principle was targeted at programmers who would try to put their computer science education to work unnecessarily -- designing complex object hierarchies, layers of abstraction, "generic" versions of functions that would work with future to-be-determined classes.

For example, Ron Jeffries, one of the founding fathers of XP, writes:
You find that you need a getter for some instance variable. Fine, write it. Don’t write the setter because "we’re going to need it". Don’t write getters for other instance variables because "we’re going to need them".
Sometimes I am in the habit of writing getters and setters for my private member variables in my AnyLogic Java classes. But why am I spending the time to do this? Because I might need it someday?

YAGNI.

Balance

YAGNI is different from "don't design anything" or blindly ignoring all feature requests from your project manager / creative team / customer. You definitely want to make sure you're looking at the big picture, knowing the end goal of your simulation model or software project.

There are other concerns you need to balance where you may choose to write code that initially seems unneeded: things like refactoring for readability, or designing for upcoming (known) milestones. And it's certainly good practice to design (and comment, and code) as if someone else might reuse your code someday. Reusability is good in this sense.

For example, this article talks about a developer who implemented serialization of his objects to flat files, because it was the fastest and easiest approach to get the milestone done. The problem was that in the very next milestone, these objects were supposed to be serialized to a database, and the mechanisms to write to that database had already been developed. By focusing blindly on what he considered to be the simplest way to solve the problem, he created additional work for the rest of the team down the road to rewrite his ostensibly "simpler" version.

That's Bad YAGNI.

The Big Bad COM Scenario Manager

On one of the intermediate releases of the Excel UI, Jonathan (whom some of you may remember) and I developed a super-abstract version of the Data Set Manager.

It had COM interface classes neatly separated from its implementation classes so that we could re-implement data set management within a different application if we ever wanted to. At the time we had been experimenting with Microsoft Access-based solutions, and we thought we might need to migrate our data set management utilities into Access VBA.

It had custom type-safe collection classes instead of native data structures so that we could use our DataSet class in other projects if we ever wanted to. At its core, a DataSet is just a zipped up collection of files, something we'd probably want to manage in other projects.

It separated the zip utility library functions from scenario management functions so that we could use the zip library independently in other applications if we ever wanted to.

It was a textbook approach toward good COM development techniques.

It was also totally unreadable and unmaintainable. Completely over-designed. When a bug popped up, it could take hours just to trace through all of the layers of abstraction to figure out what was going on. If I ever asked our dev team to investigate an open bug in the Scenario Manager, they'd immediately find 5 excuses as to why they were too busy with other project work.

Last year I finally bit the bullet and refactored this back into a single ScenarioManager assembly in the current Modeling Studio. We got rid of about 15 classes. Reduced it from 2 DLLs to 1. And you know what? You can read the thing now. It could be even cleaner, but it's a lot better than where it was.

You guys would still probably run scared if asked to debug it... but let me assure you that's for legacy reasons.

"Wouldn't it be cool if...?"

We're all creative folks. We have lots of cool ideas about how to make our models and applications better. Now how would you feel if your cool ideas were never ever used by a user, such that building them was actually a total waste of time?

Like this guy said:
The thought that you're (sic) really cool feature idea might be a complete waste of time takes some of the wind out of your sails, doesn't it? I know it does mine. Now imagine that you apply YAGNI to every aspiring new feature? Yeah, sort of depressing.
A recent study showed that 64% of software features are rarely or never used. (Hello, Outlook "Journal"!) That's not just some of your cool ideas -- that's most of them.

So why invest the time to write it, if you don't need it now and it may not be used anyway?

Conclusion

Geoff Skipton was the one who got me thinking about this the other day in New Jersey. In describing the temptation of feature creep, he used this analogy:

Say you're modeling a person walking from point A to point B. You could simply model that person moving between A and B.

Or you could consider the fact that there might be a puddle in between A and B, so the person needs to walk around the puddle, and they might trip in doing it so we need to capture the probability of tripping in that situation, and what if they need to stop and tie their shoe along the way, we might need to model that.....

YAGNI.

Finally, Paul B. MacCready, inventor of human-powered and solar-powered aircraft sums it up well, though he wasn't talking specifically about software at the time:
Treat every problem as if it can be solved with ridiculous simplicity. The time you save on the 98% of problems for which this is true, will give you ridiculous resources to apply to the other 2%.

"stop yagni" sign borrowed from
http://www.rimmkaufman.com/rkgblog/2007/10/16/rule-of-three/

6 comments:

Anonymous said...

Peyton Manning Limited Jersey axiotakix
Brian Cushing Nike Jersey axiotakix
49ers Patrick Willis Jersey axiotakix
http://whoesalenikenfljerseys.weebly.com

Anonymous said...

They tend to be uncompleted projects that were started here and there and just aren't to the point of full acceptance because the quality doesn't meet the needs of the users Erwin[url=http://www.BruceIrvinJersey.com]Bruce Irvin Womens Jersey[/url]
J That doesn't ease the fears about the injuries to their starting offenseLEGO Mindstorms NXT 2 Check them out!Pool Cue Reviews: Distinguishing Between Preference and TruthOne caveat to heed when reading pool cue reviews or listening to someone's rant or rave is that different cue brands play differently
A recreational or occasional player may never notice that the cue he or she grabs off the rack is two ounces heavier than the one they used last time Do not lift your arms to hit itThe American football season begins with preseason games starting in mid-AugustdittoTweet spantweet font-size: 24px; p Once you can do it blind[url=http://www.CalvinJohnsonJersey.net]Calvin Johnson Authentic Jersey[/url]
you can do it fine anywhere else[url=http://www.CharlesTillmanJersey.net]Charles Tillman Jersey[/url]
but trick skills are not a necessity[url=http://www.BobbyWagnerJersey.com]Bobby Wagner Authentic Jersey[/url]
and that is one of the true tips for increased basketball control Now back to Sarah Silverman

Anonymous said...

General George S They are like motivational speakers who try to encourage and motivate a certain customer to purchase a gadget that they will recommendtimestamp a > span {display: inline-block;width: 16px;background-image:url(http://images Morita was born in California and it isn't clear why he was a Packers fan#file_links[D:\NFL\UBB.txt,1,L] but it's right there on his IMDB page YouÂ’ll also need to pay an activation fee and a monthly feeThe football field is marked with numbers: 10#file_links[D:\NFL\UBB.txt,1,L] 20#file_links[D:\NFL\UBB.txt,1,L] 30#file_links[D:\NFL\UBB.txt,1,L] 40#file_links[D:\NFL\UBB.txt,1,L] 50#file_links[D:\NFL\UBB.txt,1,L] 40#file_links[D:\NFL\UBB.txt,1,L] 30#file_links[D:\NFL\UBB.txt,1,L] 20#file_links[D:\NFL\UBB.txt,1,L] and 10
ï»?Every prop bet on Brees throwing a touchdown in one of the quarters is actually plus money and can't argue with taking any of themditto81714265584705536 a { color: #0084B4;} p Yes#file_links[D:\NFL\UBB.txt,1,L] Christine Daae is elegant and Frankie Valli is cool#file_links[D:\NFL\UBB.txt,1,L] but nothing can touch the character names in Wicked (The Colts went to Super Bowl XLIV but Vinatieri was a healthy scratch20 He holds 21st place on the fortune 50 list Implement E

Anonymous said...

[url=http://longchampbagsd.hatenablog.com/]sac longchamp[/url] Soup is an awesome meal to have in your lunch Mulberry Large Heathcliffe Natural Leather Laptop Briefcase Black for Men,Buy 2013 Mulberry Outlet all at free shipping. arsenal. You can keep it in a thermos or heat insulated canteen and take it with you for a nice hot soup for lunch. Salads are great also. Drink lots of water and move more. It helps in so many ways. Watch the sodium intake.
[url=http://quizilla.teennick.com/user/longchampsoldesa/journal/]longchamp soldes[/url] If you Unique Style Mulberry Women's Alexa Leather Hobo Black Bag.All the Mulberry Bags for sale are affordable and stylish. have discovered moths in clothing, make a moth spray from a combination of one-half gallon of water, one-fourth cup of neem oil and a few drops of castile soap. Place the mixture in a spray bottle and use it as an anti-moth spray. You can also place the clothing inside the freezer for two days to kill the moth larvae..
[url=http://longchamppliagea.webnode.nl/]sacs longchamps[/url] Therefore, most of the people seek for ways to avail the discounted deals. However, it must be make sure that they are not the replicas and are worth the investment. Last but not the least; unique and elegant dior handbag remain in Low Price Mulberry Women's Bayswater Leather Clutch Black Bag for sale, the latest look of Mulberry handbags took over as most popular vogue at all times and changes the style with the changing demands.. Internet marketing is more than throwing up a web page and hoping people will come. You need keywords that are relevant to your niche. These keywords should be tested to be certain these are the keywords or phrases being used to search in your niche market. Net has offered our lives with amusement and fun. There are 1000s of points which you can do using the net. If you are jobless as well as would certainly such as to make some cash, you could begin an online business..

Anonymous said...

In my opinion you are not right. I am assured. Let's discuss it.
Quite right! It is excellent idea. It is ready to support you.
In my opinion it is very interesting theme. I suggest all to take part in discussion more actively.
I have thought and have removed the message
In my opinion it is obvious. I recommend to you to look in google.com

[url=http://shenenmaoyiww.ucoz.com/index/shenenmaoyiww/0-4][b]michael kors outlet online[/b][/url]
[url=http://cheapbags8.webstarts.com/?r=20130117030518][b]michael kors outlet online[/b][/url]
[url=http://mvpmichaelkorsoutlet2.manifo.com/][b]michael kors outlet online[/b][/url]
[url=http://shenenmaoyiyy.fashionblog.com.br/][b]michael kors outlet online[/b][/url]
[url=http://www.squidoo.com/shenenmaoyiww][b]michael kors outlet online[/b][/url]

Anonymous said...

Excuse for that I interfere … At me a similar situation. Write here or in PM.
I am sorry, that has interfered... This situation is familiar To me. Is ready to help.
It that was necessary for me. I Thank you for the help in this question.
Your idea is brilliant
The excellent answer, I congratulate

[url=http://www.shenenmaoyiw.350.com/][b]michael kors outlet online[/b][/url]
[url=http://plxv975.dhpreview.devhub.com/blog/1115870-use-printed-carry-bags-to-promote-your-products-or-sale/][b]michael kors outlet online[/b][/url]
[url=http://nl1tu8m.dhpreview.devhub.com/blog/][b]michael kors outlet online[/b][/url]
[url=http://shenenmaoyiyy.smartlog.dk/wholesale---plastic-type-bags-in-queensland-post1265012][b]michael kors outlet online[/b][/url]
[url=http://shenenmaoyiw.exteen.com/20130110/pacsafe-bags-with-anti-thievery-features][b]michael kors outlet online[/b][/url]