Skip to content
This repository was archived by the owner on Sep 24, 2023. It is now read-only.

Coding Practices

Matt N edited this page Mar 3, 2016 · 8 revisions

Below is a list of coding practices for this project in no necessary order:

  • The proper way to use brackets { } is to put them on the next new line not next to the statement.

INCORRECT

for (int i = 0; i < 5; i++) {
    // code }

CORRECT

for (int i = 0; i < 5; i++)
{
    // code
}
  • Function naming should not use camel case, rather use an underscore to separate words

INCORRECT

function getDir (param1)
{
    // CODE
}

CORRECT

function get_dir (param1)
{
    // CODE
}
  • Use the following examples for spacing that should be followed:

EXAMPLES

foreach ($x = 0; $x < 5; $x++)
$x = explode("/n", $array)
if ($x == 5 || ($x + 5 < 11 && $x + 3 < 8))
$x = array[$x]
$x = array[$x - 1]
  • Comment code as often as necessary to clarify what functions or code blocks do.
  • Avoid duplicating code. If the code is used within the same page multiple times, create a function and abstract it. Similarly, if code is duplicated across multiple pages, either put a function in one of the pages and call it from the other, or create a helper page and put the function in there.
  • A page should represent a single function or set of highly related functions. For example, a page should not contain importing and exporting DATs, but having two different files for exporting different types of DAT is unnecessary. If it's an edge case, contact the project lead for the official ruling.
  • Place a block comment before all PHP code to explain the purpose of the page, any necessary parameters, and any developer notes and TODOs. Try to avoid placing notes and TODOs in the code unless it is required for clarity.
Clone this wiki locally