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

Sandman's code convention

From FenixWiki

Revision as of 00:51, 8 May 2007 by Sandman (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Fenix Coding Convention by Sandman (work in progress)

Contents

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). Separating some words does not need a "_", but simple can be put together, making the first character of the second word a capitol. For example NET_SendVar. Here we see the section "NET" and the section "SendVar", which is further cut down to "Send" and "Var"

Constants

Constants are written in ALL CAPS.

Like: C_SCREEN, NET_ERROR_CONNECTING, B_ALPHA

Variables

Variables are written in low caps, whether they are private, local or global.

Like: ctype, graph_mode

Functions and Processes

Functions are written in low caps as well. Defining a function or process goes like so:

key_input( 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 ")".

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 parameter.

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 capitol, while the less important ones are only low caps.

Example

Begin
    key_input(_a);
    Loop
        frame;
    End
End

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