4 ms·
> The author's example is particularly poor. I thought the author's example was reasonably good, but it doesn't capture the spirit of YAGNI as I see it. Inste
by aaronbrethorst 13y ago
> The author's example is particularly poor.
I thought the author's example was reasonably good, but it doesn't capture the spirit of YAGNI as I see it.
Instead, the way I'd phrase it is: we're introducing pets to Minecraft. For now, this means a dog. Maybe we'll add chickens and cats later, but our first release of this feature will only be dogs. I could create a Pet class and a Dog class that inherits from that, but maybe we won't. Creating a class hierarchy is only going to slow me down for now, so I'll skip it for now and just create Dog.
Fast forward a couple months, and the feature is a huge success. But, instead of an interest in cats, the users are now clamoring for different breeds of dogs. Good thing I didn't waste time creating a class hierarchy rooted at Pet, because then I'd have to juggle Pet -> Dog -> {Shiba Inu, Golden Retriever, etc.} (although I'd personally implement dog breeds with new attributes on Dog, but you get the point).
Or, the feature is a flop, and is going to be cut. Good thing I didn't spend time implementing a class hierarchy because that would've been even more wasted development time. I'm glad I got the feature into market as quickly as possible to validate it.
- angersock 13y agoSure, sure, but A/B testing the feature is going to be hell of a lot easier when you can easily switch out dogs for cats for chickens for optimized dogs. You don't want to get stuck in a local design minima. Adding a class hierarchy here would've been basically free (subclass overrides for two or three behaviors, tops). Again, there are good examples out there of when YAGNI is important--this wasn't one of them.
- ollysb 13y agoIf it's so little effort to add a layer of abstraction then it will be just as easy to add it later. If you end up needing to add a feature that the abstraction would make easier then you can still go ahead and do it first. You won't have wasted any time, it's just that you added the abstraction after rather than before a different piece of work. If you don't end up needing it then your code is simpler and you haven't wasted any time.
- angersock 13y agoSir or madam, the road to hell is lined with classes whose interfaces were defined after the fact. Usually you'll end up with a bunch of special snowflake classes and some classes which actually have thought-out interfaces, just enough to make you angry. Software engineering through accretion and backporting is not, by definition, engineering.
- ollysb 13y agoPerhaps a better way to put it is that your code base develops through assimilation rather than predicting abstractions and then shoe-horning features into them. In my experience the most elegant interfaces consistently emerge from the repeated process of adding features and refactoring the code to best fit them at that time. I can't tell you how many awkward abstractions I've had to work around at earlier points in my career because the project lead is trying to get everything to fit into their grand vision. Projects developed through assimilation mature far more smoothly because the design emerges to match reality. When you try to predict abstractions projects tend to leap and lurch. The repeated cycle is prediction, stretching, breaking and then finally rewriting.
- aaronbrethorst 13y agoOf course, at the other end of the spectrum, you have ridiculously over-designed systems whose class hierarchies stand as a testament to the hubris and folly of the developers who created them. I've dealt with both, and—more frighteningly—systems that veer from one extreme to the other depending on how far behind schedule the project was at the time that particular piece of the system was implemented. And then, of course, there's lots of code that lives somewhere in a happy middle.