Chapter 14: Don t Try This at Home


Concern over potential code duplication in menus led me to do a little research. That led me to a really cool feature. I think I went down a rat hole ” what do you think?

The Idle Brain Is the Devil s Playground

In looking at the menu method from last time, I can foresee duplication of code. The method looked like this:

 void MenuInsertSection(object obj, EventArgs ea) { 
model.SetLines(textbox.Lines);
model.SelectionStart = textbox.SelectionStart;
model.InsertSectionTags();
PutText(textbox, model.LinesArray(), model.SelectionStart);
}

Now I foresee that lots of insertion methods are coming; I ve seen the stories. There will be one to insert plain code like the method here, one for those precis things at the top of the articles/chapters, and a bunch of little utility ones for articles and so on. I see duplication coming! Every one of those menu items will have a method like this one, and the only difference between those methods will be that instead of saying InsertSectionTags, a method will say something like InsertCode or InsertPrecis. Duplication, running wild! As you know, the primary coding technique we use for keeping the code clean is to remove duplication, and although I usually know what I d do to get rid of duplication, this time I m not so sure. So I m worried.

YAGNI

Now, there s an XP rule called sb YAGNI: You Aren t Gonna Need It. This rule reminds us not to borrow trouble from the future and not to implement a feature today that we don t need today. If I m not mistaken, I actually coined that rule back in the days of the original XP project, C3, when one of us would say We re gonna need ... and start suggesting that we should build something for the future. That s what makes this chapter such a sin: I m going to break that rule. We ll see what happens.




Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net