Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The names for "global" variables (variables start with a $ character) i.e. variables which have a scope beyond the current expression and are used in subsequent expressions. Global variables should have an upper case first letter e.g. $CompanyLocationCounter.

Layout for if()

Simple

For simple if(

...

    Statement 1 ,

// else

...

) statements we recommend the following style of layout:

Note that when a statement in an if() clause is more than 1 line, wrap them in a do() e.g.:

...

, for example:

Code Block
// Example code layout 
if( condition expression,
    do(
        Statement 1,

        Statement 2,

        .... Statement n
    ),

// else
    Statement A
)

Note that closing brackets should always line up with the start of the statement (see the do() and if() statements above)

Complex

For more complex if() statements we recommend the following style and that comments are added:

Code Block
// Short description on what is being achieved when the if statement is true
if ( $foo > 10 &&
     $bar == "X" &&
      ( $baz == "Y" ||
         $qux == "Z" ),

			// description of what the statement is doing
      		do (
      				Statement 1
      		),

// else, description of what the statement is doing
	Statement 2
)

Layout for switch()

Simple

For simple switch statements we recommend the following layout:

Code Block
switch(
    [ condition expression 1, Statement 1 ],
    [ condition expression 2, Statement 2 ],

// default
    _NULL
)

switch( 
	[ $foo > 100, $x = "HIGH" ],
	[ $bar > 50,  $x = "MEDIUM" ],

	// default
    $x = "LOW",
)


Advanced

Note that the _NULL statement is currently requiredFor switch statements that perform more advanced activities we recommend the following layout:

Code Block
switch (
      // description of what the statement is doing
      [$foo == 100,
           $x = "HIGH"
      ],

      // description of what the statement is doing
      [$bar == 50,
           do (
                 $x = "Medium",
				 $x = toUpper($x)
           )
      ]
      
      // default
      do (
           $x = "LOW"
      )
)