The First Test Worked

We wrote a little unit test, right in the CustomerTest file, that tested a new method, CursorLocation, which answered the cursor location given an array of lines. It just went over the array and counted characters until it found the vertical bar character. It took a little while to get that running, but just a little. Then we went to lunch , at the Lazy Lizard. (No, we aren t getting paid for these plugs.)

At lunch, I was complaining because that new SetInput method was going to loop over the lines twice, once to get the clean lines and once to get the cursor location. Obviously, that was inefficient. Where was my partner??? What were we thinking??? Everyone knows you don t work on efficiency until you have the code working. Besides that, the candidate code for doing it in a single function looks worse , not better:

 private void SetInput(StringReader reader) { 
String[] input = ArrayToEnd(reader);
int cursorLocation;
String[] newLines;
CleanInput(input, out cursorLocation, out newLines);
model.Lines = newLines;
model.SelectionStart = cursorLocation;

We just sketched this code, however, rather than typing it in, so we didn t really see how ugly it was. And we couldn t see how to write a decent unit test for it, and we had this perfectly good acceptance test, so we pushed ahead. Mostly I pushed ahead. I think after a while Chet was being swept along, while I kept thinking I was just a few more lines away from making it work. The breakdown came when I converted one method to return the new records, thus destroying its ability to be used for whatever it had done before. It was too much. And since we re working without much of a code manager and we hadn t backed up the files, we were doomed. I knew that if I would just write one more method, I could make it work. But I realized that even if I did, I could never explain it to you tonight.

Two hours of work, and that sinking feeling that you were better off before you started. What do you do?

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

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: