1 <big><b>Programming Conventions</b></big>
4 The SILC Toolkit has been programmed with a specific programming style that
5 is consistent across all libraries and interfaces. The programming style
6 defines for example naming conventions for functions, structures, macros,
7 enumerations, and other constants.
10 <br /> <br /> <br />
11 <b>Naming Conventions</b>
14 <b>Macros and Defines</b>
17 Macros are always capitalised and include underscores to separate words
18 in the name. All macros start with the "SILC_" prefix. Example:
22 #define SILC_PACKET_PADLEN(__packetlen, __blocklen) \<br />
23 SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \<br />
24 ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)
28 Also other defines (#define) are always capitalised and include
29 underscores to separate words in the name. Also all defines start with
36 All structure names begin with "Silc" prefix, and the name is mixed-case,
37 for example: SilcClientConnection, SilcCommandPayload. Many of the
38 structures used in SILC are actually private structures, and application
39 cannot access them directly. In these cases the structures are forward
40 declared in the public header, and the implementation of the structure
41 is in the source file. In these case application does not need to know
42 the contents of the structure, and is usually provided with a helper API
43 to access the structure when needed.
46 In the most of the cases the forward declaration for a structure is pointer,
50 <tt>typedef struct SilcClientStruct *SilcClient;</tt>
53 Application should always use the type defined pointer instead of the
60 Function naming uses the common naming convention used in Toolkit. All
61 functions are always lowercase and they use underscores. The name of
62 the function always starts with prefix "silc_". The name tells what
63 the function do. The name of a function is constructed from following parts:
66 <tt>silc_(module)_(function)</tt>
69 The (module) is the library, or interface this functions is part of. For
70 example: "cipher", "config", "command", "packet", etc.
73 The (function) is the description of the functionality of the function.
74 For example: "read", "new_id", "register", "find_by_name", etc. Examples:
78 silc_server_packet_send<br />
79 silc_server_packet_send_to_channel<br />
80 silc_idcache_del_by_id<br />
81 silc_schedule_init<br />
82 silc_protocol_excute_final<br />
87 When function registers something the name of the function generally is
88 "silc_function_register" and unregistering is done with
89 "silc_function_unregister". When function allocates something it
90 is "silc_function_alloc" and when freeing it is
91 "silc_function_free". Respectively, with init/uninit functions.
97 Enumerations are always capitalised and include underscores to separate
98 words in the name. All enumerations start with the "SILC_" prefix. Also,
99 usually all enumerations are type defined to a specific name which can
100 be used as type for the enumeration. Example:
105 SILC_EXAMPLE_ENUM_NONE,<br />
106 SILC_EXAMPLE_ENUM_LIST,<br />
107 SILC_EXAMPLE_ENUM_STATUS,<br />
112 The naming for the type definition for the enumerations follow the
113 normal naming convention; the name starts with "Silc" prefix and the
117 <br /> <br /> <br />
124 The indendation in the source code is 2 characters, and tabulators are
125 not used. Example piece of code:
129 void silc_client_free(SilcClient client)<br />
131 if (client) {<br />
132 if (client->rng)<br />
133 silc_rng_free(client->rng);<br />
134 silc_free(client);<br />
140 <b>Placing Braces</b>
143 Generally the braces placing the SILC code follows the K&R style; the
144 opening of the brace is put to the last on the line, and the closing brace
145 is on first on its own line, except for functions. Examples:
149 if (condition) {<br />
150 silc_something();<br />
151 silc_something_more();<br />
157 int silc_client_function()<br />
159 return 0;<br />
165 if (condition) {<br />
166 something;<br />
167 silc_something_more();<br />
169 something_else;<br />
175 if (condition) {<br />
176 something;<br />
177 silc_something_more();<br />
178 } else if (other_condition) {<br />
179 something;<br />
180 silc_something_more();<br />
182 something_else;<br />
190 Standard anti-nesting method is used in the header files to avoid
191 multiple inclusion of the header file. Example:
195 #ifndef SILCHEADER_H<br />
196 #define SILCHEADER_H<br />
198 #endif /* SILCHEADER_H */
202 All public header files have the "silc" prefix in the filename, for example:
203 silcclient.h, silcprivate.h, silcutil.h. There are other header files in
204 the Toolkit as well. Application should not directly include these headers,
205 however if needed it may access them.
208 Every header file also includes a copyright notice.