GWU

CS 1111

Introduction to Software Development

GWU Computer Science


CS 1111 Code Style

This guide contains basic examples that show the coding style that will be enforced in this class.
The comments above or after each line indicate the number of the style rule.




Beginner

  • Option 1: This example shows "Egyptian Bracket Placement" placement.
  • Here, the opening curly bracket "{" is placed at the end of the line where the block is named, and closed with "}" at the same indent level as the p in the word public of the block.

|-- indent Level 1
    |-- indent Level 2
        |-- indent Level 3
public class SimplePrint1 { // opening bracket 1

    public static void main(String[] args) { // opening bracket 2
        // statements are indented once
        System.out.println("Hello, World!");
        System.out.println("How are you?");
    } // closing bracket 2
} // closing bracket 1
      

  • Option 2: This example shows "Aligned Bracket Placement"
  • Here, the opening curly bracket "{" is placed under the p in the word public of the block, and closed with "}" at the same indent level as the p in the word public of the block.

|-- indent Level 1
    |-- indent Level 2
        |-- indent Level 3
public class SimplePrint2
{ // opening bracket 1

    public static void main(String[] args)
    { // opening bracket 2
        // statements are indented once
        System.out.println("Hello, World!");
        System.out.println("How are you?");
    } // closing bracket 2
} // closing bracket 1
      




Intermediate




Advanced