Inicio Â» VIVOE Documents Â» Styling code for developers

Styling code for developers

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.

 

<< Noviembre 2024 >>
DomLunMarMieJueVieSab
272829303112
3456789
10111213141516
17181920212223
24252627282930
25.08.2005
Microsoft está haciendo los ajustes definitivos de Sparkle, que según sus planes competirá con el muy establecido Macromedia Flash. Se espera un anuncio para septiembre.
18.11.2005
Google permite consultar gratuitamente cómo ha encontrado la gente tu sitio a través de su sistema de búsqueda. Decide que palabras clave cortar y cuales agregar a tus páginas para que te encuentren más fácil.
31.10.2005
Hmos cambiado la técnica del scroll ahí. Parece ser que el sitio de Huracán Wilma ha legado a una pausa
26.08.2005
Llega el ex presidente de México a la entidad bajo un fuerte dispositivo de seguridad; se traslada a la comunidad chiclera Pol-Noh, a unos 100 kilómetros de esta ciudad capital
25.08.2005
Google lanzó el 24 de agosto su primer servicio de mensajería instantánea, que incorpora funciones de chat y comunicación por voz. En los hechos, el gigante de las búsquedas entra a competir con MSN Messenger, Yahoo y Skype.
22.08.2005
Señala el precandidato presidencial que, en su momento, el gobierno federal actual cumplió con reubicar las bases militares, liberar a presos zapatistas e impulsar los Acuerdos de San Andrés