Skip to content

Latest commit

 

History

History
96 lines (92 loc) · 2.57 KB

File metadata and controls

96 lines (92 loc) · 2.57 KB

Code rules

  1. In 3 days before deadline must be test and review.
  2. No "magic" numbers and constants in code. Everything must be in enums, defines or special variables.
  3. Use global variables only after team discussion.

Code style:

  1. Every figure "{" must be on same string.
     fun Foo(a : Int) {
         ...
     }
  1. Single if-else must be with " { ... }".
     fun Foo(a : Int) {
       if (n > 0) {
        ...
       }
       else {
       ...
       }
     }
  1. Naming.
  • camelCase for: local variables, class members
  • PascalCase for: functions
  • snake_case for: data types (except types declared in the libraries used)
  • UPPER_CASE for: global constants, enumerations elements, macro constants
     val PI_CONSTANT = 3.1415926;
     
     class my_class {
         var memberData : Int
   	  fun ProcessData() {
   	  }
     };
     
     fun Foo(a : Int) {
   	 val maxNumber = 0
        val ballForceThrow = 0.0
     }
     
     fun OpenFile() {
     ...
     }
  1. Indentation
  • Use only spaces, 4 spaces
  • Any inner block must be indented
  • Data access specifiers ("public", "protected", "private") has same indentation as class
  • "case" markers has same indentation as "switch" block
class my_class {
    public fun ProcessData() {
        when (memberData) {
        0 -> memberData++
        1 -> memberData--
        2 -> printf("Error")
        }
    }
    private val memberData : Integer
};
  1. If function fits the screen, variables declares in the beginning, else in the place of use.
  2. Insert spaces between operators and operands.
     val x = (a + b) * c / d + foo()
  1. Each variable declaration on a new line.
    var x = 3
    val y = 7
    val z = 4.25
  1. When the line gets longer than 100 characters, divide it into two, making a newline after the operator, and continue writing.
  val result = reallyLongFunctionOne() + reallyLongFunctionTwo() + 
       reallyLongFunctionThree() + reallyLongFunctionFour()
  1. Leave blank lines between functions and between expression groups.
 fun Foo() {
  ...
 }
                        // Empty line
 fun Bar() {
  ...
 }
  1. Each function and each class must be started with comment, which will explain in simple way what this function/class do.
// parse string to array of tokens. Returns true in case of success and false otherwise
fun Parser(s : String) {
 ...
}