The Current Code


We think that s a lot more expressive. Here s the whole method. See whether you agree that we have made it more expressive and whether we re justified in taking out the comments we removed:

 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 ( newlines.Count == 0 ) {
newlines.Add( "<P></P>" );
selectionStart = 3;
return;
}

newlines = new ArrayList();
newlines.AddRange(LinesThroughCursor());
newlines.AddRange(NewParagraph());
newlines.AddRange(LinesAfterCursor());

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

This code still isn t done, as we ll suggest in a moment, but you can see what s happened : we ve taken code that clearly needed some explanation and we ve replaced it with code that surely needs less explanation. You might prefer a bit more than we do, but we ll wager that most readers won t want one line of comment per line of code anymore.




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