This wiki is out of date, use the continuation of this wiki instead

Sandman's code convention

From FenixWiki

(Redirected from Sandman's coding convention)
Jump to: navigation, search

Fenix Code Convention by Sandman (work in progress)

Contents

[edit] Indenting

Indenting is done with four spaces or a tab of four spaces wide. The Program-, Process-, Function-, Global-, Local-, Public-, Private- and Begin-statements are always completely to the left, with no indentation at all. The exception to this is inside the Declare block, in which case Public and Private are indented once. Declaration of variables are indented once. Precompiler-statements are generally to the left as well, but for small blocks they can be indented. The code between Begin and End statements are indented once at first.

See the example for a visual representation.

[edit] Names

Separating sections of a name is done by use of the "_" character. An easy example is the function NET_Init. "NET" is a different section than "Init", because the first denotes the origin of the function and the second denotes what the function does. Another example is NET_ERROR_CONNECTING: "NET" denotes the origin, "ERROR" denotes a more precise origin (an error) and "CONNECTING" denotes what the constant means (error while connecting).

[edit] Constants

Constants are written in all upper case.

Like: C_SCREEN, NET_ERROR_CONNECTING, B_ALPHA

[edit] Variables

Variables are written in lower case, whether they are private, local or global. When defining a struct, the name of the struct start with a capital and is accessed with a capital as well. For example "Mouse.left". "Mouse" is a struct, so it's typed with a capital and "left" is a normal variable, so it's in lower case.

The datatype of the variables are always noted when declaring them, even when they're integers.

Like: ctype, graph_mode, Scroll

[edit] Types

Types are written in both case, but mostly in lower case. A type starts with a "_", for example, Network.dll has the type "_IPaddress".

[edit] Defines

Defines are, like constants, written in all upper case. On top of this, the following way of defining can be used, to prevent multiple includes of the same file. Note the "__".

#ifndef __MYFILENAME_MYFILEEXTENSION
#define __MYFILENAME_MYFILEEXTENSION
// Place the file's code here.
#endif

This is done in Network.dll:

#ifndef __NETWORK_FH
#define __NETWORK_FH
// Network.fh code
#endif

[edit] Functions and Processes

Functions are written in both cases. Defining a function or process goes like so:

keyInput( int keycode, int pointer status)

The "(" comes directly after the function name, followed by a " " (space) and the datatype of the first parameter, before a space and the name of the first parameter. Then a "," and the whole thing starts again, ending with a ")".

While a process is declared using Process in all versions of Fenix, it is not so simple with functions. When the Function statement wasn't used, the functions were to be defined by putting the return type in front of it, which mostly was an integer. Later, when the Function statement came effective, that statement was to be used before the function name instead of the return type.

For naming a function or process, separating some words with a "_" is not needed, but can simply be put together, making the first character of the second word a capital. For example NET_SendVar. Here we see the section "NET" and the section "SendVar", which is further cut down to "Send" and "Var". First sections denoting the origin are typed in capitals, while the other sections only begin with a capital.

Calling a function or process isn't bound to any rules, because in many cases, the clarity of the code is different, even though the code is written the same. So just best suit the layout of the code to the environment. In general though, a good look is created by the use of a " " (space) before every argument.

[edit] Control-flow keywords

Control-flow keywords can be typed in two ways. The difference denotes the importance of the statement. The important control-flow statements are typed with the first character a capital, while the less important ones are only lower case.

[edit] Example

Const
    KEY_TARGET = _a;
End
Global
    int key_pressed;
End

Process Main()
Begin
    keyInput(KEY_TARGET,&key_pressed);
    Loop
        if(key_pressed)
            say("Key pressed!");
        end
        frame;
    End
End

Process keyInput( int keycode, int pointer status)
Begin
    Loop
        if(key(keycode))
            *status = true;
        else
            *status = false;
        end
        frame;
    End
End
Personal tools