Indent style protocol
The following style protocol applies to the writing style used for PHP, Javascript and Actionscript produced by Digitart.
Most of the time we follow the code standards defined in PEAR, but with some exceptions that should be considered before writing code for Digitart.
We base our styling mainly on the K&R style, described briefly here, that keeps the first opening brace on the same line as the control statement, indents the statements within the braces, and puts the closing brace on the same indentation level as the control statement (on a line of its own):
int main(int argc, char *argv[]) { ... while (x == y) { something(); somethingelse(); if (some_error) do_correct(); else continue_as_usual(); } finalthing(); ... }
However, a big difference between traditional K&R style and ours is that we use this opening brace style ALSO in the functions and class statements tough. This is because the need of inserting the opening brace on a new line came from a specific requirement of the original C language to make a difference between statements with arguments and statements without arguments.
This diferentiation do not applies to PHP, Javascript and ActionScript, thus there's no need to use a whole new line only to mark a new opening structure or declaration.
Some styling guidelines as PEAR's states that using the opening brace on a new line helps to keep blocks of code vissualy appart becausethey are separated by virtual "blank lines".
This advantage is lost when statments inside the statement uses closing braces on blank lines also.
We prefer to save those "blank lines" in favor of having more meaningful lines of code on the screen at the same time. Modern IDEs allow to colapse blocks of code so we prefer to have something like:
function myFunc(){
if($condition){
//action
}
}
that will be colapsed as
function myFunc() .... +
instead of
function myFunc()
{... +
Our coding style seems to be more related with Flash's actionscript code styling. Anyway, we prefer code styling that let us have more lines of meaningful code on the screen at the same time.
Indentation
Except for flash's actionscript, we use only "soft" indentation, described as a group of 4 spaces, and avoid using TABs. Most IDEs allows to define if TAB key will produce a real TAB or a group of spaces. We always prefer spaces because it will keep the same structure despite the program you may use to edit the code.
On Flash's code editor, this can't be changed and there's no point to do so because most of the time as code is edited and handled on the Flash/Flex editor. Whenever you have to citate, copy or paste Actionscript code, we will prefere to keep the TABs.