Editor Project 2 Review/Discussion

Lecture Notes for CS 190
Spring 2016
John Ousterhout

  • Click here for .java file containing examples.
  • Every project improved considerably in Project 2. The overall class decomposition is pretty good or better in every project.
  • Remaining issues are mostly secondary ones.
  • Most common problem: special cases and inconsistencies
    • Example 1: method too specialized. Better to separate into two different methods, one for horizontal and one for vertical.
    • Example 2: inconsistent argument ordering
    • Example 3: loop statement suggests one order, but body suggests a different order. Maybe better to have 2 different loops?
    • No newline for the last line of the file under some conditions?
    • Are newlines counted in line lengths even if not represented?
  • Design away special cases
    • Try to eliminate if statements.
  • Classes for user interface were still muddy in many cases
    • Example 4:
      • No documentation for Editor class, name too generic (class appears to be the controller)
      • EditorPanel appears to be the view (would be useful for comment
        • say what this class *doesn't* do).
      • EditorPanel handles mouse events (should be Editor)
      • Editor handles focus events (should be EditorPanel)
    • Example 5:
      • Unclear what TextEditorGUI does.
      • TextEditorPanel shouldn't need to know about TextEditorController.
  • Each class should stand for something (what does each instance correspond to?)
  • GUI classes for editor:
    • One class that displays text in a window, along with an insertion cursor and selection, and keeps the display up-to-date as the text changes, window is scrolled/resized, etc.
    • One class that implements the GUI for editing text in a window
    • Optionally, could combine the above two classes, but they are almost completely independent.
      • View must provide methods for managing the selection and cursor, and for translating between document and screen coordinates.
    • One class that represents a file being edited, along with all of the windows that currently display the file. This class is the one that gets invoked to open a new window on a file. It's also a natural place to store the active window for undoing.
  • A few documentation issues:
    • Example 6
    • Example 7