1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/doc/en/arch_coding.txt
Dado Sutter 17487f9ebe - doc folder replaced by some work done on Led Lab for the new doc and site
- This should actually be a merge but we made a mistake on the initial repo creation
  and a merge was not possible.
- Below there is a resumed log of the commit messages for the few steps, just for
  the record.

- The merged commit messages for this work are:

 - Removing Portuguese doc content
 - Ignore folder names fixed on .gitignore
 - Removed doc files which content migrated to the CMS
 - docdata.lua updated accordingly
 - Doc build checked ok
 - Overall doc structure and contents still being refined
 - Removing folder cache from git versioning
 - Removing folder dist from git versioning. The folders above are generated by the buildall.lua script and are not part of the sources
 - Adding .gitignore file with objects info to inform git what to ignore
 - Removed file
 - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
 - Moving all files and folders to a working doc folder
 - Css updated
 - Index page added and CSS adjusts
 - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
 - Signed-off-by: Guilherme Sanchez <guilhermesanchezpacheco@gmail.com>
 - Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
 - files deleted
 - Changed function that creates functions submenus.
 - Menu inserted with árvore, CSS adjusts, google search
 - Changed past design to new design
 - CSS updated
 - initial import

- The commit ids were also preserved but they are related to this "other"
  work done on Led Lab. We'll keep the repo just in case.

4dce3f77c47b0c3001a2075a946e80ee52759b49 - Removing Portuguese doc content
78d8847525cacf045fe7e672cff6bd1e058a6a4b Ignore folder names fixed on .gitignore
48dee6b7962168ab1098bf709ead6f3cfe6b7964 - Removed doc files which content migrated to the CMS - docdata.lua updated accordingly - Doc build checked ok - Overall doc structure and contents still being refined
2aa2fe0c554db03dbc7029c34d0f4500fe625b37 - Removing folder cache from git versioning - Removing folder dist from git versioning   The folders above are generated by the buildall.lua script and are not part of the sources - Adding .gitignore file with objects info to inform git what to ignore
af6cc2890edf1855af319dc999a03feee5f9bee0 Removed file
6a180e72eb4f4860620cafc0685000e9f2174cfe Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
eb430112e78ae537459ab315e228ebca84bdf2d4 Moving all files and folders to a working doc folder
d28a7c99489915630bd2625f3756fecf0d08ce37 Css updated
32836ffe382f04ab07c3e6f018c7b449a20d7a8d Index page added and CSS adjusts
1461d9957d9d25a1467cb57ab8717aa213a37e8d Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
ae1934c04f35a29e25bb4495ae8a31cd9c000b5b Signed-off-by: Guilherme Sanchez <guilhermesanchezpacheco@gmail.com>
b5f31d70f1fac8d3fba325c9867a03f976775698 Merge branch 'master' of git@repos.giga.puc-rio.br:elua-doc.git
ec9ad8446b7ea38b252c6a416e70774349835e45 files deleted
bd7a80151b2030720ba8d8a303467d8c25a4b4b2 Changed function that creates functions submenus.
6a7494acaec694fadbb13520bcbccc51a6b95dfe Inserido menu com árvore, ajustes no CSS, busca do google
e979f1c259d425c9a3be83f9cda20eddffe073bb Changed past design to new design.
381459e95286886b052103a0253e60b29e064d7a CSS updated
4f81d2f1195efe733fe5f97517be325d75937bc3 initial import
2011-05-06 06:49:21 -03:00

205 lines
6.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// $$HEADER$$
The eLua coding style
---------------------
This section presents the eLua coding style that should be followed by every developer working on eLua. The following rules apply:
1. Everything should be spaced out properly. Examples (please note the spacing rules, which is basically "space out everything for readability"):
+
---------------
i = 3 (not i=3)
a = ( a + 5 ) / 3
for( i = 0; i &lt; 10; i ++ ) ...
if( ( i == 5 ) && ( a == 10 ) ) ...
unsigned i = ( unsigned )p;
void func( int arg1, const char* arg2 ) ...
---------------
2. *Indentation*: indent everything at 2 SPACES. Again, *SPACES*. [warning]#DO NOT USE TABS#. This is important (and fortunately pretty easy to remember :) ).
There are too many examples where tabs completely destroyed the readability of source code. Most editors have an "insert
spaces instead of tabs" option; use it, and set your "tab size" to 2. +
Also, indent "{" and "}" on their own lines:
+
------------
if( i == 2 )
{
// some code here
}
else
{
// some other code here
}
-----------
+
Or:
+
---------------
void f( int i )
{
// function code
}
---------------
+
Do not enclose single statements in {} when given a choice. For example, do this:
+
------------
if( i == 2 )
return;
------------
+
instead of this:
+
------------
if( i == 2 )
{
return;
}
------------
+
Also, follow the "one statement per line" rule. In other words, don't do this:
+
------------------
if( i == 2 ) return;
------------------
+
Do this instead:
+
-----------------
if( i == 2 )
return;
-----------------
+
Note that eLua code does not use a space between the function name and its parameter list when calling/defining it (like in the Lua code, for example). So do this:
+
---------------
void f( int i )
{
// function code here
}
f( 2 ); // function call
---------------
+
instead of this:
+
---------------
void f ( int i )
{
// function code here
}
f ( 2 ); // function call
---------------
3. *line terminators*: [warning]#THIS IS IMPORTANT# Use UNIX style (LF) line terminators, not DOS (CR/LF) or old Mac (CR) line terminators.
4. *identifier names*: use a "GNU-style" here, with underlines and all lowercase:
+
------------------
int simple;
double another_identifier;
char yes_this_is_OK_although_quite_stupid;
------------------
+
As opposed to:
+
------------------
int Simple1;
double AnotherIdentifier;
char DontEvenThinkAboutWritingSomethingLikeThis;
------------------
5. *DO NOT USE HUNGARIAN NOTATION* (like iNumber, sString, fFloat ... if you don't know what that is, it's fine, as it means that we don't need to worry about it :) ). It has its advantages
when used properly, it's just not for eLua.
6. *constants in code*: don't ever write something like this:
+
-------------
if( key == 10 )
sys_ok();
else if( key == 5 )
phone_dial( "911" );
else if( key == 666 )
{
while( user_is_evil() )
exorcize_user();
}
else if( key == 0 )
sys_retry();
else
sys_error();
-------------
+
Instead, define some constants with meaningful names (via enums or even #define) and write like this:
+
-------------
if( key == KEY_CODE_OK )
sys_ok();
else if( key == KEY_CODE_FATAL_ERROR )
phone_dial( "911" );
else if( key == KEY_CODE_COMPLETELY_EVIL )
{
while( user_is_evil() )
exorcize_user();
}
else if( key == KEY_CODE_NONE )
sys_retry();
else
sys_error();
-------------
+
You can see in this example an accepted violation of the "one statement per line" rule: it's OK to write "else if (newcondition)" on the same line.
7. use specific data types as much as possible. In this context, *specific data types* refers to generic types that have the same size on all
platforms. They are defined by each platform in turn and their meaning is given below:
+
--
* *s8*: signed 8-bit integer
* *u8*: unsigned 8-bit integer
* *s16*: signed 16-bit integer
* *u16*: unsigned 16-bit integer
* *s32*: signed 32-bit integer
* *u32*: unsigned 32-bit integer
* *s64*: signed 64-bit integer
* *u64*: unsigned 64-bit integer
By writing your code to take advantage of these specific data types you ensure high portability of the code amongst different hardware platforms. Don't
overuse this rule though. For example, a *for* loop has generally an *int* index, which is perfectly fine. But when you specify a timeout that
must fit in 32 bits, definitely declare it as *u32* instead of *unsigned int*.
--
8. *endianness*: remember that eLua runs on both little endian and big endian architectures so write your code accordingly.
9. *comments*: we generally favor C++ style comments (//), but it's perfectly OK to use C style (/\**/) comments. The use of automatic documentation generators like Doxygen isn’t encouraged,
since they tend to make the programmer over-document the code to the point where it becomes hard to read because of the documentation alone. Ideally, you'd neither over-document, nor
under-document your code; just document it as much as you think is needed, without getting into too much details, but also without omitting important information. In particular, DON'T do this:
+
-----------------
// This function returns the sum of two numbers
// Input: n1 - first number
// Input: n2 - the second number
// Output: the sum of n1 and n2
int sum( int n1, int n2 )
{
return n1 + n2;
}
-----------------
+
When something is self-obvious from the context, documenting it more is pointless and decreases readability.
10. *pseudo name-spaces*: since we don't have namespaces in C, I like to "emulate" them by prefixing anything (constants, variables, functions) in a file with something that identifies that
file uniquely (most likely its name, but this is not a definite rule). For example, a file called "uart.c" would look like this:
+
-------------------------------
int uart_tx_count, uart_rx_count;
int uart_receive( unsigned limit )...
unsigned uart_send( const char *buf, unsigned size )...
-------------------------------
Also, if you're using 3rd party code (from a library/support package for example) making it follow the above rules is nice, but not mandatory. Focus on functionality and writing your own
code properly, and come back to indent other people's code when you really don't have anything better to do with your time.
// $$FOOTER$$