Behold! What follows is the best code I have ever written and will ever write. Even I, its creator, am awestruck at its flexibility and simplicity.

It is a marvelous thing! It cannot break, does exactly what it was designed to do, and will not ever need to be refactored.

It cannot be improved upon!

In my future endeavors, I shall have to work my hardest to merely approach the profound wonder of this code snippet.

Forevermore will I be comparing all the code I write to this masterpiece.

It is perfect!

Look upon my work, ye mighty, and applaud! For I, a lowly web programmer, have created the single most perfect piece of code in the history of programming:


OK I might have gone a bit too far with that last one. Ahem.

All joking aside, I've long been a proponent of a philosophy I think of as extreme deletionism, which in my mind is a very strict interpretation of YAGNI. This philosophy can be summed up as: code needs a reason to exist, and if no reason can be immediately surmised, that code needs to be refactored or, in the best case, deleted.

Anything that doesn't have an immediately and incredibly obvious purpose (relative to someone with at least a working knowledge of the scope and purpose of the project) probably isn't truly necessary.

And if it isn't truly necessary, why does it need to exist?

This is something I stress to my team: you need to have a reason to do what you are doing, and that reason shouldn't be "well this would be nice to have." You should need the feature you're working on, not just want it, and be able to prove to me why you need or will need it in the near future it should I (or my boss, or anyone else) ask.

All of this is why I included YAGNI in my Good Code Basic Training post: I truly believe that YAGNI is one of the most fundamental guidelines a programmer can use. Obviously it is not a hard-and-fast rule, but simple and discerning applications of it, in my experience, lead to a lot less confusion and wasted time.

The logical extreme of my position is that the best code is no code at all. I think that's an admirable goal, one we should be striving for regularly. Clearly we can't have no code at all literally, but to aim for less code than you previously had should be one of the goals we keep in mind every day.

In short: YAGNI saves time. I have a limited amount of time to spend on anything, including learning and reading code, so I don't want to waste a second of it. Don't waste your time (or others') on features you don't truly need!