Coding Standards

From ESEEWiki

Jump to: navigation, search

Contents

If statements:

  • Put parentheses around every condition
  • Brackets only required for multiple lines
  • Comment under the if statement
  • Brackets get their own lines
  • Else if on same line
if ((condition1) && (condition2))
// comment explaining the if condition
{
   ...
}
else if (condition1)
// comment explaining the if condition
{
   ...
}

Functions:

  • Function name in lowercase or camelCase
  • Comments under function header as shown
function functionName($arg1, $arg2)
// takes:       string, string
// returns:     string
// description: this function does...
{

}

Variables:

  • Note in PHP variable types don't exist
  • Variable names in lowercase or camelCase
int myAwesomeVar;
string name;

Comments:

  • Above line of code if longer or a sentence
  • To the right of line if a clause or short
// what the below code does
something.function($arg1, $arg2);

OR?

something.function($arg1, $arg2);   // elizabeth's way

Classes:

  • Keep member variables private, and use public getter functions
  • Class names start with capital letters
  • Each class has a private member variable, $db, to access the database
class Section
{
  private $sectionId;
  $this->db->runQuery(...);
}
Personal tools