Skip to content

Code Conventions

SkyReMore edited this page Feb 14, 2016 · 43 revisions

Here's will be some information about our code conventions.

I've searched some for some formal methods of code's formatting, but I guess everyone just doing it as they get used to. And also we have Java Code Conventions (http://www.oracle.com/technetwork/java/codeconventions-150003.pdf), with some complicated rules... So I think I'll just put some of them here to create a basis, and the rest we will add later.

1. Files

  • Files longer than 2000 lines are cumbersome and should be avoided
  • File name should always starts with uppercase letter. If we need to add more words in file's name we're connect them in one, using uppercase as discriminator (example "File", "SomeFile", "SomeVeryBigFile", etc.)
  • This rules not acting on the assets files (such as pictures or sounds). They can be any suitable size and name

2. Imports

(under development for now)

3. Comments

  • (3.1) Each comment starts with a new line (nothing should be before comment in this line)

    Not our method:

    `int i;           `  
    ` describedStatement();  // Some comment   `                         
    

    Correct method:

    int i;
    // Some comment
    describedStatement();

  • (3.2) Each comment's sentence starts with capital letter (also better to use punctuation)

    `/*                                              `   
    ` * Some comment                                 `   
    ` * I just want to say how good are programm is! `  
    ` * Blah.                                        `  
    ` * Blah, blah.                                  `  
    ` * Blah, blah, blah, blah.                      `  
    ` */                                             `  
    
  • (3.3) Adding comments strictly before described statement

    ` // Some comment`  
     `class DescribedStatement {`  
     `..`  
     `......`  
     `...`  
     `}`  
    
  • (3.4.1) If you need only one line - use //

    ` // Some comment`  
     `void describedMethod {`  
     `..`  
     `......`  
     `...`  
     `}` 
    
  • (3.4.2) If you need more than one line (if you comment is too long or just to express your thoughts better) - use block comments like in example above

      /*    
       * Some comment   
       * I need more lines!  
       * I said MORE lines!!    
       * And thats not the end   
       * Ok, I said everything  
       */  
       void describedMethod {  
       ..  
       ......  
       ...  
       }     
    

4. Whitespaces

  • Two blank lines should always be used in the following circumstances:

    • Between class and interface definitions

     class SomeClass {  
         public void doSomething() {  
            float delta = 10;  
               	       
            for (int i = 0; i < delta; i++)   
     	      delta++;   
       }   
    

    }

      // This class is useful   
     class SomeClass2 {   
         public void doSomething() {  
            float delta = 10;  
               	       
            for (int i = 0; i < delta; i++)   
     	      delta++;  
       }    
    

    }

  • One blank line should always be used in the following circumstances:

    • Between methods

    public void doSomething() {
    float delta = 10;

    for (int i = 0; i < delta; i++)
    delta++;
    }

    // This method searching for something
    public int searchSomething() {
    }

    • Between the local variables in a method and its first statement

    public void doSomething {
    float delta = 10;

    for (i = 0; i < delta; i++)
    ``delta++
    ...
    }

5. Classes

  • Class name should starts with uppercase letter. If we need to add more words in file's name we're writing them as one, using uppercase as desriminator (example "Class", "SomeClass", "SomeCreativeClass", etc.)

6. Methods

  • Method name should starts with lowercase letter. If we need to add more words in file's name we're writing them as one, but first letters of extra words is uppercase (example "method", "someMethod", "someCoolMethod", etc.)

7. Fields

(under development for now)

8. Lines

Each line should contain at most one statement.

 public void doSomething {  
 float delta = 10;  
 delta--;   
 delta++  
 delta = delta + 10
 delta *= 20.5f;   
 }  

9. Arithmetic

(under development for now)

10. For, while statements

(under development for now)

11. If-else, swith-case statements

(under development for now)

12. Try/catch statements

(under development for now)


Of course thats not everything, so new paragraphs will be created as we will need them here.

Clone this wiki locally