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

Sandman's code convention

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 00:51, 8 May 2007 (edit)
Sandman (Talk | contribs)

← Previous diff
Revision as of 10:39, 8 May 2007 (edit) (undo)
Sandman (Talk | contribs)

Next diff →
Line 1: Line 1:
Fenix Coding Convention by Sandman (work in progress) Fenix Coding Convention by Sandman (work in progress)
 +
 +== Indenting ==
 +Indenting is done with four spaces or a tab of four spaces wide. The [[Program]]-, [[Process]]-, [[Global]]-, [[Local]]-, [[Private]]- and [[Begin]]-statements are always completely to the left, with no indentation at all. 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.
== Names == == 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 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 ==
-Constants are written in ALL CAPS.+Constants are written in all upper case.
Like: [[C_SCREEN]], [[NET_ERROR_CONNECTING]], [[B_ALPHA]] Like: [[C_SCREEN]], [[NET_ERROR_CONNECTING]], [[B_ALPHA]]
== Variables == == Variables ==
-Variables are written in low caps, whether they are private, local or global.+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.
-Like: [[ctype]], [[graph_mode]]+The datatype of the variables are always noted when declaring them, even when they're integers.
 + 
 +Like: [[ctype]], [[graph_mode]], [[Scroll]]
 + 
 +== 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".
 + 
 +== 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 "__".
 +<pre>
 +#ifndef __MYFILENAME_MYFILEEXTENSION
 +#define __MYFILENAME_MYFILEEXTENSION
 +// Place the file's code here.
 +#endif
 +<pre>
 +This is done in [[Network.dll]]:
 +<pre>
 +#ifndef __NETWORK_FH
 +#define __NETWORK_FH
 +// Network.fh code
 +#endif
 +<pre>
== Functions and Processes == == Functions and Processes ==
-Functions are written in low caps as well. Defining a function or process goes like so:+Functions are written in both cases. Defining a function or process goes like so:
-<pre>key_input( int keycode, int pointer status)</pre>+<pre>keyInput( int keycode, int pointer status)</pre>
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 ")". 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.+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]].
== Control-flow keywords == == 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.+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.
== Example == == Example ==
<pre> <pre>
 +Const
 + KEY_TARGET = _a;
 +Global
 + int key_pressed;
Begin Begin
- key_input(_a);+ keyInput(KEY_TARGET,&key_pressed);
Loop Loop
 + if(key_pressed)
 + say("Key pressed!");
 + end
frame; frame;
End End
End End
-Process key_input( int keycode, int pointer status)+Process keyInput( int keycode, int pointer status)
Begin Begin
Loop Loop
Line 45: Line 82:
End End
End End
 +</pre>

Revision as of 10:39, 8 May 2007

Fenix Coding Convention by Sandman (work in progress)

Contents

Indenting

Indenting is done with four spaces or a tab of four spaces wide. The Program-, Process-, Global-, Local-, Private- and Begin-statements are always completely to the left, with no indentation at all. 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.

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

Constants

Constants are written in all upper case.

Like: C_SCREEN, NET_ERROR_CONNECTING, B_ALPHA

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

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

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
<pre>
This is done in [[Network.dll]]:
<pre>
#ifndef __NETWORK_FH
#define __NETWORK_FH
// Network.fh code
#endif
<pre>

== Functions and Processes ==
Functions are written in both cases. Defining a function or process goes like so:
<pre>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.

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.

Example

Const
    KEY_TARGET = _a;
Global
    int key_pressed;
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