Coding Guidelines

From GregariusWiki

Jump to: navigation, search

Theme and Plugin authors are encouraged to follow these coding guidelines:

[edit] No PHP short tags

Short PHP tags (such as <? ... ?> and <?= $variable ?>) aren't supported on several systems and are therefore not allowed in Gregarius.

Instead you should use the full PHP tags declarations (<?php ... ?> and <?php echo $variable ?> respectively)

[edit] Braces

Braces are mandatory, even when they are not strictly required! Expressions such as the following are not allowed:

if ($condition)
  do_something();
while ($i++ < 5) echo $i;

These are correct:

if ($condition) {
  do_something();
}
while ($i++ < 5) {
  echo $i;
}

By convention braces should be in-line with the block condition, e.g. not...

if ($level_1_cond)
{
  if ($level_2_cond)
  {
    echo "cheers we reached level two!";
  }
}

... but:

if ($level_1_cond) {
  if ($level_2_cond) {
    echo "cheers we reached level two!";
  }
}

[edit] Identifier Naming Conventions

  • Variable and method names should be spelled in lowerCamelCase
  • Function names should be spelled in C-style all_lowercase_underscore()
  • Constants should be ALL_UPPERCASE_UNDERSCORED
Personal tools
Advertisement