Observations and Conclusions

Take a look at the InsertParagraphTag method as it now stands:

 public void InsertParagraphTag() { 
// On Enter, we change the TextModel lines to insert, after the line
// containing the cursor, a blank line, and a line with < P >< /P > . We set the
// new cursor location to be between the P tags: < P > < /P > .
// handle empty array special case (yucch)
if ( lines.Count == 0 ) {
lines.Add( "<P></P>" );
selectionStart = 3;

lines.InsertRange(LineContainingCursor()+1, NewParagraph());

// set cursor location
selectionStart = NewSelectionStart(LineContainingCursor() + 2);

Frankly, I think that s getting rather clean. And each step from the original ugly version to this one was a simple refactoring, supported by tests that told us that we weren t breaking anything. (Well, OK, the first couple of refactorings weren t test-supported. That was risky, but I got away with it this time.) Since then, things have gone faster and we ve been much more confident. I even felt pretty safe working alone on this chapter, because the tests Chet and I had devised were working for us even when he was home with his wife, where he belongs on a Saturday. Here s the thing to remember: sb automated tests record our intelligence for use later!

Now, the most irritating part that still remains in the InsertParagraphTag method is that special case for an empty array. I d like to clean that up sometime, but not right now. And the selectionStart doesn t satisfy me entirely. I m tempted to move that searching code to the get method that returns the variable. That would let me remove this line. But I m not sure that will work, because the cursor setting depends on the size of the tag inserted. I ll talk about that with Chet next time we get together. It s a pretty small wart, I think.

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

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