Skip to content
OwlScream edited this page Oct 9, 2014 · 13 revisions

Desing Patterns

The definitions of how to code the FSMDriver will be built over the premise that the pilot is programmed in the C++ language, so, it goes without saying that the commands and pieces of code provided in this Design Patterns section are valid for C++ arquives of extension ".cpp" and ".h" inside this repository.

  1. Structural Design Patterns

This sections defines the format in which the variables, constants, methods and other parameters of the codes should be created and referred to.

1.1. Variables and Methods/Functions declarations

Variables and Methods/Functions will start with lower case letters and from the second word and on, capital letters at the beginning of every word, as follows:

type_T nameOfVariable;
type_T nameOfMethod(type_T nameOfParameter1, type_T nameOfParameter2);

1.2. Constants declarations

Constants will have their names in capital letter, to their full extent, as follows:

const type_T NAMEOFCONSTANT = value;

1.3. Indentation style

The size of a tab inside the codes will be defined as 4, that is, an indentation is what could be replaced as 4 spaces, in a visual matter. Further on, indentation style will be defined as K&R style, which consists of: the command (header), followed by the opening brace in the same line, then the statements within the command (inside the braces, beginning in the line after the header) are indented (+1 tab difference related to the header of the command), and finally the closing brace in the same indentation level as the header, as follows:

int main(int argc, char *argv[])
{
    ...
    while (x == y) {
        ...
        doSomething();
        if (error) {
            correctError();
        } else {
            continueNormally();
        }
    }
}

Observations: The main method will have the opening brace in the following line instead of the same line. else conditions will be inserted in the same line of their corresponding if. Also, instructions will have spaces between parenthesis, braces, mathematical operations, etc, with the exception of the first and last letters inside of them, and the parenthesis immediately after a method call or definition, as follows:

if (x + y == 15) {
    callMethod1(type_T parameter1, type_T parameter2);
    callMethod2(type_T parameter);
} else {
    x = (y + 15) / 15;
    callMethod2(type_T y);
}

1.3. Pointers

Pointers will have their symbols immediately before variables, NOT TYPES OF VARIABLES, as follows:

type_T *variable1, *variable2, *variable3;

The same definition goes for the situations where a pointer argument is passed, the reference sign will be attached to the variable name, as follows:

type_T method(typeAddress &address)

[to be continued...]

Clone this wiki locally