CS 127: Data Structures
Java Programming Style Directives

Good programming style makes your code much more readable and maintainable. Here are some basic style directives that I expect you to follow in your code. Here is a template for structuring your Java classes, which I encourage to you use.

  1. Line up braces. You may have used method (a) in your intro class. The textbook uses method (b), which also happens to be my personal method. Either method is equally acceptable. Consistency is the key here: pick one and stick with it.

    Method (a) Method (b)
      if (a == b)
      {
          c = d;
          e = f;
      }
      if (a == b) {
          c = d;
          e = f;
      }
  2. Use whitespace in a meaningful way to make your code readable.

  3. Use capitalization and descriptive names to make your identifiers clear.

  4. Declare your variables with appropriate access.

  5. Keep your methods short. A method shouldn't be longer than 1-2 screens without good reasons.

  6. Each class header should contain documentation containing

    You may use Javadoc to accomplish this, and I encourage you to do so.

  7. Each method should contain header documentation containing

    You may use Javadoc to accomplish this, and I encourage you to do so.