O'Reilly logo

Extreme Programming Adventures in C# by Ron Jeffries

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Expressing Ideas

Just for something to do, I decided to clean up some code. Here’s what happened—not all of it good!

Something to Do

I think I’ll refactor the code a bit, just for something to do. Let’s take a look. Here’s the method that handles Enter:

public void Enter() {
  int cursorLine = CursorLine();
  String[] newlines = new  String[lines.Length+2];
  for(int i = 0; i <= cursorLine; i++)  {
    newlines[i] = lines[i];
  }
  newlines[cursorLine+1] = "";
  newlines[cursorLine+2] = "<P></P>";
  for (int i = cursorLine+1; i < lines.Length; i++) {
    newlines[i+2] = lines[i];
  }
  lines = newlines;
  selectionStart = NewSelectionStart(cursorLine + 2);
}

Here are some of the ideas that went into this code:

  • Handle the Enter key.

  • Change the lines table to include a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required