Coding Style in SILC source tree
================================
-This documents describes the coding style and coding conventions used
+This document describes the coding style and coding conventions used
in the SILC source tree. The purpose of the document is to describe the
common way to program for SILC and thus should be learned when programming
new code. The document describes various conventions regarding variable
have a pretty good idea what you are programming and what the module
does. For example, <cipher>, <config>, <command>, <packet>, etc.
-The <function> is the describtion of the functionality of the function
+The <function> is the description of the functionality of the function
you are writing. Naturally it should be self explanatory and weird
short names should be avoided. It is better to have long function
names than some odd name that does not tell what it is about. Function
==================
The code should be clean and good to eye, although the function of it
-must always superseed the appearance. However, it is nice to read code
+must always supersede the appearance. However, it is nice to read code
that looks good. Here are some issues on general appearance.
o Use empty lines when appropriate but not too much. There
o If you are not sure about how something should be done or
the code you've done is not finished, it should be commented
- with XXX plus explanation what is going on.
+ with XXX plus explanation what is going on. For example,
+ /* XXX hmm... how is this flushed? */
Source Files
All source files starts with header that includes the name of the author,
copyright notice and the copyright policy, usually part of GNU GPL licence.
-Now, if this really isn't that important but some sort of header should
-be in all source files.
+Now, this really isn't that important but some sort of header should be in
+all source files.
In the start of the source files should include the #include's that are
needed. All library source files must include `silcincludes.h', this is
public prototypes of the functions. Go see any header file as an example.
+Using gotos
+===========
+
+Gotos are used in the SILC code quite often. If you know how to use
+goto's properly then it is ok to use them for example to optimize the
+code. However, if you don' know how to use goto's do not use them.
+
+
Debug Messages
==============
You should always use silc_calloc instead of silc_malloc because
silc_calloc automatically zeroes the allocated memory area. This is
-imporant especially with structures because generally we want that all
+important especially with structures because generally we want that all
fields, by default, are zero.
So, instead of doing
memset(ptr, 'F', sizeof(*ptr));
silc_free(ptr);
-Where 'F' indicates free'd memory if you ever check it with debugger.
+Where 'F' indicates free'd memory if you'd ever check it with debugger.
Other choice is to use 0 instead of 'F'. The pointer after freeing
should be set to NULL if appropriate, ptr = NULL.
Note that some functions in the SILC library handles the zeroing of
the memory area automatically, like for example, silc_buffer_free.
+Also note that all allocation routines assert()'s if the memory allocation
+fails, ie. system does not have free memory.
+
Callback Programming
====================