overview edit doc new doc remove

Jan 26, 2018

How to write code

Comments

Single line

Start with lowercas, space between the comment beginning and the actual comment.

// this is a comment

# this is also a comment

Mutliline

If multiline comments are applicable write your comment in between, not on the same line as the comment defining characters. Also start with a tab.

/*
 *  your
 *  comment 
 *  resides
 *  here
 */

If stars are not possible, you don't need to write them.

<--
  |  your
  |  comment
  |  resides
  |  here
-->

Variables

If the code allows it use spaces before and after an equal sign.

myVar = "I am a variable"

var myVar = "I am a variable"

Constants

Write a constant in uppercases.

CONSTANT1 = 6;

constant CONST1 = "the constant"

Mathematical operations

a + b
d += 4

Functions

function func1 (parameter1, parameter2, parameter3) {

  // do something

}

func1 () {

  code

}

Function parameters

Write a space between the comma and the next parameter.

function func1 (para1, para2, para3, para4) {

  // some code

} 

Calling a function with parameters

If you want to call a function with parameters:

function1(para1, para2, para3)

Loops

if..else..

For writing if else structures and the code within is only a single line, don't write brackets if the code allows it. Note the space beteween the if and the parentheses.

if (the condition)
  // this is the single line of code
else
  // i am the other single line of code

else use enters.

if (the condition) {

  // code
  // more code

} else {

  // more code
  // some more code

}

when else if statement is used write like:

if (the condition) {

  // code

} else if (another condition) {

  // more code

} else {

  // last piece of code

}

Ternary operation

Short if else statement.

return (variable2 > 50 ? true : false)

Switch

For writing switch statements use enough enters.

switch (variable) {

  case 'A':

    this is what happens if A

    return

  case 'B':

    this is what happens if B

    return

  default:

    the default code block

}

For

for (i = 0; i < 8; i++) {

  // some code

}

SQL

Write SQL statements in uppercase.

SELECT * FROM db1 WHERE a > b
1