Re: YAGNI's and Planning for Change
Posted: Jul 14, 2005 4:14 PM
> Sorry if that sounded a little terse, Chris. I was
> posting quickly :)
I am sorry, I didn't think you were terse and I am sorry if I came across as sounding standoffish :-)
> To me, the key thing that makes code
> refactorable is tests. Everything else is gravy.
> The only thing I do that could really be mistaken for
> YAGNI-violation is to keeping classes and methods focused
> on single responsibilities. Some people look at code like
> that and think it is over-engineered because it consists
> of lots of small pieces, but to me it isn't, it's just
> well factored.
Yes I fully agree! Small functions, small classes, and small units. It is far easier to work with this kind of code, and you can often recombine the pieces in new and interesting ways. Programming like that leads to reusable code.
> Interfaces are easy to add when you need them so I let
> need justify them. If I need to mock something out, it
> gets an interface. If something gets more than a couple
> of users, it gets an interface.
I think I see, your point is refactor early and frequently, before it is too expensive? I think we fundamentally agree, its just that we differ on precisely when to do this; early, or preemptively. I am just really lazy and hate rewriting code. So I prefer to preempt the refactoring, I find that since I do it out of habit, it takes no extra development time.
> I think that Alexandrescu's policy based design is great,
> but I wouldn't adopt it wholesale as an approach for
> application level code. I can imagine refactoring into
> those sorts of solutions if the need arose, but to me,
> doing it from the start is too anticipatory unless you are
> writing a library.
Yes, the policy class design is sometimes overkill.
> One thing that I don't think we talk about enough is how
> there are significant differences between writing library
> code and writing application code.
At this point I don't agree. In my experience the code which is easiest to work with, is code which is written most like a library (but without the YAGNI's).