views:

670

answers:

6

As I've increasingly absorbed Agile thinking into the way I work, yagni ("you aren't going to need it") seems to become more and more important. It seems to me to be one of the most effective rules for filtering out misguided priorities and deciding what not to work on next.

Yet yagni seems to be a concept that is barely whispered about here at SO. I ran the obligatory search, and it only shows up in one question title - and then in a secondary role.

Why is this? Am I overestimating its importance?

Disclaimer. To preempt the responses I'm sure I'll get in objection, let me emphasize that yagni is the opposite of quick-and-dirty. It encourages you to focus your precious time and effort on getting the parts you DO need right.

Here are some off-the-top ongoing questions one might ask.

Are my Unit Tests selected based on user requirements, or framework structure?

Am I installing (and testing and maintaining) Unit Tests that are only there because they fall out of the framework?

How much of the code generated by my framework have I never looked at (but still might bite me one day, even though yagni)?

How much time am I spending working on my tools rather than the user's problem?

When pair-programming, the observer's role value often lies in "yagni".

Do you use a CRUD tool? Does it allow (nay, encourage) you to use it as an _RU_ tool, or a C__D tool, or are you creating four pieces of code (plus four unit tests) when you only need one or two?

+9  A: 

TDD has subsumed YAGNI in a way. If you do TDD properly, that is, only write those tests that result in required functionality, then develop the simplest code to pass the test, then you are following the YAGNI principle by default. In my experience, it is only when I get outside the TDD box and start writing code before tests, tests for things that I don't really need, or code that is more than the simplest possible way to pass the test that I violate YAGNI.

In my experience the latter is my most common faux pas when doing TDD -- I tend to jump ahead and start writing code to pass the next test. That often results in me compromising the remaining tests by having a preconceived idea based on my code rather than the requirements of what needs to be tested.

YMMV.

tvanfosson
Just thought I'd mention that I'd point out that I mentioned this post in a blog post: http://jasonmbaker.wordpress.com/2009/01/11/enemies-of-test-driven-development-part-ii-yagni/
Jason Baker
A: 

I have seen a lot of posts on SO referencing premature optimization which is a form of yagni, or at least ydniy (you don't need it yet).

Jim Anderson
I wonder what you call it when you prematurely optimize what you don't need in the first place? :)
le dorfier
le dorfier: epic waste of time? (ewot) :D
jalf
+4  A: 

Yagni and KISS (keep it simple, stupid) are essentially the same principle. Unfortunately, I see KISS mentioned about as often as I see "yagni".

In my part of the wilderness, the most common cause of project delays and failures is poor execution of unnecessary components, so I agree with your basic sentiment.

MusiGenesis
I, too, agree with the basic sentiment about project delays, but don't agree YAGNI and KISS are the same. I have seen much simple code that is not needed, and complex code that is needed.
Dour High Arch
KISS should really be KIASAN (keep it as simple as necessary). A simple component that is unnecessary is still more complicated than it needs to be - nothing is simpler than nothing (NISTN?).
MusiGenesis
A: 

I don't see YAGNI as the opposite of quick-and-dirty, really. It is doing just what is needed and no more and not planning like the software someone writes has to last 50 years. It may come rarely because there aren't really that many questions to ask around it, at least to my mind. Similar to the "don't repeat yourself" and "keep it simple, stupid" rules that become common but aren't necessarily dissected and analyzed in 101 ways. Some things are simple enough that it is usually gotten soon after doing a little practice. Some things get developed behind the scenes and if you turn around and look you may notice them may be another way to state things.

JB King
+2  A: 

The problem I find is that people tend to bucket even writing factories, using DI containers (unless you've already have that in your codebase) under YAGNI. I agree with JB King there. For many people I've worked with YAGNI seems to be the license to cut corners / to write sloppy code.

For example, I was writing a PinPad API for abstracting multiple models/manufacturers' PINPad. I found unless I've the overall structure, I can't write even my Unit Tests. May be I'm not a very seasoned practioner of TDD. I'm sure there'll be differing opinions on whether what I did is YAGNI or not.

Vyas Bharghava
Factory spam makes me barf. Often, all that's needed is a higher order function to serve as a factory. And even *more* often, no factory is needed at all, but it's the Golden Hammer that is easy to understand.
dss539
+3  A: 

The freedom to change drives YAGNI. In a waterfall project, the mantra is control scope. Scope is controlled by establishing a contract with the customer. Consequently, the customer stuffs all they can think of in the scope document knowing that changes to scope will be difficult once the contract has been signed. As a result, you end up with applications that has a laundry list of features, not a set of features that have value.

With an agile project, the product owner builds a prioritized product backlog. The development team builds features based on priority i.e., value. As a result, the most important stuff get built first. You end up with an application that has features that are valued by the users. The stuff that is not important falls off the list or doesn't get done. That is YAGNI.

While YAGNI is not a practice, it is a result of the prioritized backlog list. The business partner values the flexibility afforded the business given that they can change and reprioritized the product backlog from iteration to iteration. It is enough to explain that YAGNI is the benefit gained when we readily accept change, even late in the process.

Cam Wolff