4 ms·
I never understood this objection. The interface adds flexibility in the present - it allows other classes to depend on an abstraction instead of a concrete cla
by mdpopescu 8y ago
I never understood this objection. The interface adds flexibility in the present - it allows other classes to depend on an abstraction instead of a concrete class. The future is absolutely irrelevant here, since YAGNI.
- pjc50 8y ago> it allows other classes to depend on an abstraction instead of a concrete class. ... which has exactly zero concrete advantages if there's only one implementation of the class.
- asianthrowaway 8y agoA good programmer plans ahead. Edit: of course it is up to individual judgement on a case by case basis, and there are instances were it is obvious that no other concrete implementation of an interface will be required. But otherwise, writing an interface is good practice because it helps safeguard against time consuming future refactoring.
- titzer 8y agoThis is exactly what YAGNI is meant to counter: the constant tendency of programmers to add speculative extension capabilities that are never used. These add complexity and cognitive overhead. It's a net loss. Also, people pretend like refactoring is hard. My experience is that refactoring is only hard on the ends of the spectrum, where someone has added all the wrong abstractions, or no abstractions at all. Of the two, I'd prefer the latter, but obviously anything in the middle is usually better.
- pjc50 8y ago> A good programmer plans ahead The comment above said the opposite, that the future was irrelevant. These days there are tools that can help in a lot of languages; it's not a time consuming operation to press the Resharper "extract into abstract interface" button.
- wpietri 8y agoNo. I get why you think this way, as I also used to. Good programmers may think ahead, but they don't build ahead.
- gaius 8y agoShow me a guy who says YAGNI and I’ll show you a guy who has coded their way into a corner that the only way out is a total rewrite. Why do you think webdevs throw everything away every couple of years?
- krapp 8y ago>Why do you think webdevs throw everything away every couple of years? Because their bosses tell them to and because it looks better on their resume, not because the code they have suddenly stops working. Chances are you're not gonna need it. Chances are you don't even need most what you do have.
- wpietri 8y agoFrom what I've seen, web devs throw everything away every couple of years due to high technology volatility, high requirements volatility, management idiocy, and outright business failure. As well at lack of automated testing that is exacerbated by the many technologies that make that hard. And in environments like that, YAGNI makes even more sense. Overbuilding now in hopes it will pay off later is never a great idea. But it can only ever pay off if you correctly predict your business and technological future accurately. When you guess wrong, it's just waste.