lasso/HACKING

60 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

============
Coding Style
============
- Use explicit ``!= NULL``, ``!= 0``, etc. This makes code easier to read
and remove warnings on some platform. Don't forget SPACES before and
after the comparison operator.
Examples:
BAD:
2004-08-04 23:24:48 +02:00
``if (a)``
BAD:
2004-08-04 23:24:48 +02:00
``if (a!=NULL)``
GOOD:
2004-08-04 23:24:48 +02:00
``if (a != NULL)``
GOOD:
2004-08-04 23:24:48 +02:00
``if (a != 0)``
- Put figure brackets ``{}`` even if you have only one operator
in ``if``, ``for``, etc. This also makes code easier to read and
saves a lot of time when you need to quickly change something.
Examples:
BAD:
.. line-block::
2004-08-04 23:24:48 +02:00
if (a != NULL)
message(G_LOG_LEVEL_MESSAGE, "Ko");
GOOD:
.. line-block::
2004-08-04 23:24:48 +02:00
if (a != NULL) {
message(G_LOG_LEVEL_MESSAGE, "Ok");
}
- Put SPACES before the opening round bracket and after the closing round
2004-08-05 02:15:21 +02:00
bracket with ``if``, ``for``, ``switch``, ``while``, etc. One more time,
it improves the readability of the code.
2004-08-04 23:24:48 +02:00
Examples:
BAD:
.. line-block::
if(a != NULL){
message(G_LOG_LEVEL_MESSAGE, "Ko");
}
GOOD:
.. line-block::
if (a != NULL) {
message(G_LOG_LEVEL_MESSAGE, "Ok");
}
- Check for memory leaks.
2004-08-05 00:00:12 +02:00
I recommend valgrind (http://valgrind.kde.org) utility with options:
2004-08-04 23:59:23 +02:00
--leak-check=yes
--show-reachable=yes
--num-callers=32
--suppressions=tests/valgrind/openssl.supp