CSCI 2300 Coding Standards

(Adopted and modified from Google Java Style Guide)

Formatting

  1. Braces: in CSCI 2300 we will use Allman style brackets. Example:
    
              while (x < y)
              {
                 doSomething();
                 doSomethingElse();
              }
           
  2. Empty blocks: may be concise
    
               //this is acceptable
               void doNothing(){}
             
  3. Block indentation: Each time a new block or block-like construct is opened, the indent increases by three spaces. When the block ends, the indent returns to the previous indent level. The indent level applies to both code and comments throughout the block. Tab character is NOT to be used for indentation, use ASCII horizontal space character (0x20) instead>.
  4. White spaces: a single white space is used to separate any reserved word, for example if, for, while, from open paranthesis (() that follows on that line. A white space will separate statements of a for-loop.
    
           // this is ok
           for (int i = 0; i < x; i++)
           {
              // execute some statements
           }
    
           // this is NOT ok
           for(int i = 0; i < x; i++)
           {
              //execute some statements
           }
           // this is NOT ok
           for (int i = 0;i < x;i++)
           {
              //execute some statements
           }
    
           
  5. Column limit: 100. Java code has a column limit of 100 characters. Any line that would exceed this limit must be line-wrapped.

Naming conventions

  1. Class names: classes are named according to what they represent. The name must be in CamelCase, starting with a capital letter.
  2. Directory names: directory names do not have white spaces in them.
  3. Variable names: variables are named according to what they represent. The name must be in camelCase, starting with a lower case letter.
  4. Method names: methods are named according to what they do. The name must be in camelCase, starting with a lower case letter.

Committing code to git

  1. The .class files should never be committed to the git repositories
  2. All committed code must compile using the Java compiler of hopper.slu.edu. You may develop your code using any Java compiler you want. I will be compiling your code on hopper.slu.edu.