1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
$Id$
Table of Content
1. Introduction
2. Names of Header Files
3. Definitions of Types, Functions etc
3.1. Prefixes
3.2. Function Definitions
3.3. Type Definitions
3.4. Enum Elements
3.5. Macro Definitions
3.6. Callbacks
4. Formal Style
4.1. Indent Style
4.2. Brackets
4.3. Start of Files
5. ChangeLog
6. BUILD Version Number
7. Versioning
8. CVS Usage
9. Documentation
1. Introduction
===============
This file contains some style guidelines which I would like to see respected
by all authors contributing code to this project.
Nobody will wrench off your head if your submission does not follow these
guidelines, but you should be aware that your code will most likely be
modified to comply to this document.
The goal of these guidelines is to keep the project files uniform and thus
making it easier to read them.
This document is subject to changes, and the project admin is open for
discussion and suggestions.
I know that many parts of this project do not fully comply to this
style guide but I am working on it.
2. Names of Header Files
========================
For every module there may optionally be these header files:
- MODULENAME.h prototypes and type definitions to be exported
- MODULENAME_p.h prototypes and type definitions to be used by the module
only (these files are not installed)
- MODULENAME_l.h prototypes and type definitions to be used by the library
only (these files are not installed)
MODULENAME must be the name of the module (like error) in all-lowercase
letters (this is to avoid problems with file systems which do not support
case sensitive file names).
3. Definitions of Types, Functions etc
======================================
Every type, function, macro etc that is exported must be introduced by the
keyword "GWENHYWFAR_API".
This is needed for WIN32 platforms to inform the compiler about which
symbols are to be imported from this project.
Every function must have a prototype.
For exported functions they should be in the modules header file, for
non-exported functions these should be in the "MODULENAME_p.h" or in the
"MODULENAME_l.h" file.
Example: GWENHYWFAR_API void GWEN_DB_Group_free(GWEN_DB_NODE *n);
3.1. Prefixes
-------------
Every function or type name has two prefixes:
- GWEN_
This forms a namespace "GWEN" which prevents function name
collisions
- a module name
This makes every function name unique within GWEN.
The module name should be all-capitals if the name is shorter than three
characters or is an abbreviation.
It should start with a capital otherwise.
Please note that even internal functions (i.e. those which are not to be used
outside the library) MUST have these prefixes.
Examples: GWEN_DB_Values_Count, GWEN_Error_GetType
3.2. Function Definitions
-------------------------
Function names consist of multiple words combined by underscores.
Every word after the prefixes starts with a capital.
If any word itself consists of multiple sub-words (like in GetType) then
every sub-word should start with a capital, too.
This improves the readability of the code.
There is one exceptions from this rule (for historical reasons):
Functions which are constructors, destructors or duplication functions (like
GWEN_Buffer_new, GWEN_Buffer_free, GWEN_Buffer_dup) need to have the last word
start with a lowercase letter.
These functions also should use the given words below:
- _new for constructors
- _free for destructors
- _dup for deep copy duplications
Example: GWEN_DB_Values_Count, GWEN_Error_GetCode, GWEN_Error_new
3.3. Type Definitions
---------------------
Types are written in all-capitals, like in GWEN_DB_NODE.
Do not export structs per se. It is important that the real structure of the
structs used within Gwen is hidden. Members of structs must be accessed using
getter and setter functions.
This makes sure that applications always use pointers instead of creating
objects directly. This also reduces the number of incompatible API changes
(those changes make it necessary for every depending package to be recompiled
and thus should be avoided where possible).
3.4. Enum Elements
------------------
New enum elements should consist of multiple words which are concatenated
(like in GWEN_LoggerLevelError).
Unfortunately the enum definitions inside the GWEN_DB module do not follow
this guideline in this regard. Since changing this would produce many problems
this rule only applies to new enum definitions.
3.5. Macro Definitions
----------------------
Macro names are written in all-capitals, like in GWEN_DB_FLAGS_DEFAULT.
3.6. Callbacks
--------------
Callbacks must be attributed using "GWENHYWFAR_CB" to make them work. Best
known callbacks in Gwenhywfar are those of the GWEN_INHERIT framework.
The following example illustrates this:
void GWENHYWFAR_CB MyType_FreeData(void *bp, void *p);
As you can see the return type is followed by the keyword GWENHYWFAR_CB which
expands on WIN32 platforms to "__stdcall". This makes it possible to use such
callbacks on WIN32, too.
BTW: In a Linux environment this macro is expanded to an empty string because
Linux doesn't need such an attribute.
However, using the macro GWENHYWFAR_CB make the source code protable.
4. Formal Style
===============
4.1. Indent Style
-----------------
The preferred style is GNU: two space indent.
4.2. Brackets
-------------
The preferred style here is to have the opening bracket at the very same
line as the keyword which introduces the block, like in:
if (pos) {
if (pos>=bf->bufferSize) {
DBG_ERROR(0, "Position outside buffer");
return -1;
}
}
The closing bracket is supposed to be alone in the next line following the
block (as seen above).
4.3. Start of Files
-------------------
Every source file (*.{c, cpp, h}) should have a header like this:
------------------------------------------------- X8 cut here
/***************************************************************************
$RCSfile$
-------------------
cvs : $Id$
begin : Tue Sep 09 2003
copyright : (C) 2003 by Martin Preuss
email : martin@libchipcard.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
------------------------------------------------- X8 cut here
The copyright and email entry should of course be adapted ;-)
All files within this project are licensed under the GNU LGPL, and the header
of every file must reflect that (as is in the header above).
5. ChangeLog
============
Every change to the CVS version of this project should be accompanied by
a descriptive text in the file ChangeLog.
The format of such an entry should match that of the existing entries,
currently these are emacs-style and "my style" ;-)
However, the format does not really matter, as long as it contains the
following information:
- date of change
- name of the author of the changes
- description of the change
If the change breaks compatiblity with the previously existing version of this
project then this should be marked.
6. BUILD Version Number
=======================
The file "configure.ac" contains a line which sets the BUILD version number
(GWENHYWFAR_VERSION_BUILD=xyz).
Please update this number after a change (and just before committing your
changes)..
This has to do with the latency of the CVS server: Public CVS lags some hours
behind developer CVS, because public access is served from the CVS backup.
The BUILD version number allows to identify the version if some user wants to
try the current CVS version of this project but only draws an older version
because of the latency.
7. Versioning
=============
Starting with version 1.0 the following versioning scheme is to be used:
- if there are changes to the API which do not make it necessary to change
the SO_MAJOR version (no addition to the API etc) then only the patchlevel
version is incremented
- if there are changes which require the SO_MAJOR version to be incremented
then:
- if the SO_AGE is also incremented (i.e. there are downward compatible
additions to the API) the minor version number is incremented and the
patchlevel is reset to 0.
- if the SO_AGE is reset to 0 (i.e. the new API is not compatible to the
old one) the major version is incremented and the other version parts
are reset to 0.
Starting with version 1.4.2 the version numbers of released packages always
use three digits.
Examples:
- version 1.2.1 has the same SO_MAJOR as 1.2.2, so 1.2.2 can completely
replace 1.2.1 and vice versa without any problems
- version 1.3.0 is downward compatible to 1.2
- version 1.4.0 as well
- version 2.0.0 is incompatible with 1.x
8. CVS Usage
============
Please make sure that a commit to CVS does not make the CVS repository
unusable, so before committing:
- check whether your local version compiles correctly
- check whether the library/executable created actually DOES work
This is necessary because the CVS version is actually used by testers and the
developers. So rendering the CVS version unusable would be disastrous...
9. Documentation
================
Every exported function and type should be documented inside a header file.
This project uses doxygen for this purpose.
Well, not every function is documented right now, but I am working on
that ;-)
Martin Preuss, Hamburg/Germany, Feb 27 2006
|