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 defines (#define) are always capitalised and include underscores to
29 separate words in the name. Also all defines start with the "SILC_" prefix.
35 All structure names being with "Silc" prefix, and the name is mixed-case,
36 for example: SilcClientConnection, SilcCommandPayload. Many of the
37 structures used in SILC are actually private structures, and application
38 cannot access them directly. In these cases the structures are forward
39 declared in the public header, and the implementation of the structure
40 is in the source file. In these case application does not need to know
41 the contents of the structure, and is usually provided with a helper API
42 to access the structure when needed.
45 In the most of the cases the forward declaration for a structure is pointer,
49 <tt>typedef struct SilcClientStruct *SilcClient;</tt>
52 Application should always use the type defined pointer instead of the
59 Function naming uses the common naming convention used in Toolkit. All
60 functions are always lowercase and they use underscores. The name of
61 the function always starts with prefix "silc_". The name tells what
62 the function do. The name of a function is constructed from following parts:
65 <tt>silc_(module)_(function)</tt>
68 The (module) is the library, or interface this functions is part of. For
69 example: "cipher", "config", "command", "packet", etc.
72 The (function) is the description of the functionality of the function.
73 For example: "read", "new_id", "register", "find_by_name", etc. Examples:
77 silc_server_packet_send<br />
78 silc_server_packet_send_to_channel<br />
79 silc_idcache_del_by_id<br />
80 silc_schedule_init<br />
81 silc_protocol_excute_final<br />
86 When function registers something the name of the function generally is
87 "silc_function_register" and unregistering is done with
88 "silc_function_unregister". When function allocates something it
89 is "silc_function_alloc" and when freeing it is
90 "silc_function_free". Respectively, with init/uninit functions.
96 Enumerations are always capitalised and include underscores to separate
97 words in the name. All enumerations start with the "SILC_" prefix. Also,
98 usually all enumerations are type defined to a specific name which can
99 be used as type for the enumeration. Example:
104 SILC_EXAMPLE_ENUM_NONE,<br />
105 SILC_EXAMPLE_ENUM_LIST,<br />
106 SILC_EXAMPLE_ENUM_STATUS,<br />
111 The naming for the type definition for the enumerations follow the
112 normal naming convention; the name starts with "Silc" prefix and the
116 <br /> <br /> <br />
123 The indendation in the source code is 2 characters, and tabulators are
124 not used. Example piece of code:
128 void silc_client_free(SilcClient client)<br />
130 if (client) {<br />
131 if (client->rng)<br />
132 silc_rng_free(client->rng);<br />
133 silc_free(client);<br />
139 <b>Placing Braces</b>
142 Generally the braces placing the SILC code follows the K&R style; the
143 opening of the brace is put to the last on the line, and the closing brace
144 is on first on its own line, except for functions. Examples:
148 if (condition) {<br />
149 silc_something();<br />
150 silc_something_more();<br />
156 int silc_client_function()<br />
158 return 0;<br />
164 if (condition) {<br />
165 something;<br />
166 silc_something_more();<br />
168 something_else;<br />
174 if (condition) {<br />
175 something;<br />
176 silc_something_more();<br />
177 } else if (other_condition) {<br />
178 something;<br />
179 silc_something_more();<br />
181 something_else;<br />
189 Standard anti-nesting method is used in the header files to avoid
190 multiple inclusion of the header file. Example:
194 #ifndef SILCHEADER_H<br />
195 #define SILCHEADER_H<br />
197 #endif /* SILCHEADER_H */
201 All public header files have the "silc" prefix in the filename, for example:
202 silcclient.h, silcprivate.h, silcutil.h. There are other header files in
203 the Toolkit as well. Application should not directly include these headers,
204 however if needed it may access them.
207 Every header file also includes a copyright notice.