| 1 | THIS README IS INTENDED FOR DEVELOPERS |
|---|
| 2 | ====================================== |
|---|
| 3 | |
|---|
| 4 | (use 2 spaces for tab-stops to read/modify this document) |
|---|
| 5 | |
|---|
| 6 | Who should read this? |
|---|
| 7 | This document is written for people who do development on Licq. |
|---|
| 8 | Everyone who modifies parts of the source is a potential developer |
|---|
| 9 | and should read on :) |
|---|
| 10 | |
|---|
| 11 | What is this README all about? |
|---|
| 12 | This document describes the preferred coding and |
|---|
| 13 | documentation style for Licq and it's Plugins. |
|---|
| 14 | |
|---|
| 15 | Why should i code and document my source in a special way? |
|---|
| 16 | Many people develop on the same code and everyone wants |
|---|
| 17 | to easily read and understand it. You have your own style |
|---|
| 18 | of coding of course and we respect this fact. But when |
|---|
| 19 | you work on Licq sources you should respect our coding |
|---|
| 20 | style as well and anyways it's a great improvement when |
|---|
| 21 | we all agree to a common style so that everyone can easily |
|---|
| 22 | read understand the code. |
|---|
| 23 | |
|---|
| 24 | The Documentation is generated automatically by a tool called |
|---|
| 25 | Doxygen. It can provide descriptions and explanations for |
|---|
| 26 | every class/method/slot/attribute/you-call-it of the source. |
|---|
| 27 | This is very comfortable, but requires the source code to be |
|---|
| 28 | commented in a special (easy) manner. |
|---|
| 29 | It's no big deal and the result is brilliant, believe me! :-) |
|---|
| 30 | |
|---|
| 31 | Please also have a look at the Doxygen Website: http://www.doxygen.org |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | OK, WHAT ARE THE RULES? :) |
|---|
| 36 | ========================== |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | Indentation: |
|---|
| 41 | |
|---|
| 42 | Tabs are 2 characters, and thus indentations are also 2 characters. |
|---|
| 43 | The idea behind indentation is to clearly define where a block |
|---|
| 44 | of control starts and ends. Please keep this in mind and use |
|---|
| 45 | indentation when it's useful. |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | Placing braces: |
|---|
| 50 | |
|---|
| 51 | Braces are an issue that comes up everytime in C(++) styling. |
|---|
| 52 | The preferred way to place braces for Licq developers is to |
|---|
| 53 | place braces on a line of its own: |
|---|
| 54 | |
|---|
| 55 | if (x is true) |
|---|
| 56 | { |
|---|
| 57 | we do y |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | The closing brace is put on a line of its own, too: |
|---|
| 61 | |
|---|
| 62 | if (x is true) |
|---|
| 63 | { |
|---|
| 64 | we do y |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | { |
|---|
| 68 | we do z |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | Naming: |
|---|
| 74 | |
|---|
| 75 | Always try to choose short names. But always ensure that the |
|---|
| 76 | name is descriptive enough to let code-readers know what the |
|---|
| 77 | name stands for. If you need a variable that stores a |
|---|
| 78 | temporary value, don't call it "ThisVariableIsATemporaryCounter", |
|---|
| 79 | better call it "tmp". |
|---|
| 80 | Use mixed case when you choose a descriptive name: "refCounter" |
|---|
| 81 | the first character is always small. |
|---|
| 82 | Put the object type in front of object name. In example a button |
|---|
| 83 | is called "btnClose", a multi-line-edit is called "mleMyLongText". |
|---|
| 84 | Same applies to functions, methods and slots. |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | SOURCE DOCUMENTATION: |
|---|
| 89 | ===================== |
|---|
| 90 | Everything can get a brief and detailed description. |
|---|
| 91 | You can add a brief (one-line) description by writing something |
|---|
| 92 | like this: |
|---|
| 93 | |
|---|
| 94 | /*! \brief This is a short one-line description */ |
|---|
| 95 | void FooBar::slot_ok (bool bFoo) |
|---|
| 96 | { |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | A detailed description can contain multiple lines and should |
|---|
| 100 | be written like this: |
|---|
| 101 | |
|---|
| 102 | /*! This is a detailed description of class FooBar. |
|---|
| 103 | * Please notice that a detailed description is spreaded |
|---|
| 104 | * over multiple lines :) |
|---|
| 105 | */ |
|---|
| 106 | void FooBar::FooBar (bool Foo, unsigned short Bar) |
|---|
| 107 | { |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | The main difference between Doxygen and regulary C++ comments is the |
|---|
| 111 | additional exclamation mark (!). |
|---|
| 112 | Every description is written directly in front of the declaration of |
|---|
| 113 | the object you want do describe. |
|---|
| 114 | Please also have a look at Doxygen's website: |
|---|
| 115 | http://www.doxygen.org |
|---|
| 116 | |
|---|
| 117 | Take a look at this complete example: |
|---|
| 118 | |
|---|
| 119 | --- example --- |
|---|
| 120 | /*! \brief creates a add-user dialog. |
|---|
| 121 | * |
|---|
| 122 | * A new dialog window is created by this class. It provides a |
|---|
| 123 | * QLineEdit which takes the UIN of the user who should be added. |
|---|
| 124 | * In addition it contains a checkbox which indicates wether the |
|---|
| 125 | * remote user should be notified or not. |
|---|
| 126 | */ |
|---|
| 127 | class AddUserDlg (CICQDaemon *s, QWidget *parent) |
|---|
| 128 | : QDialog(parent, "AddUserDialog") |
|---|
| 129 | { |
|---|
| 130 | public: |
|---|
| 131 | AddUserDlg(); |
|---|
| 132 | ~AddUserDlg(); |
|---|
| 133 | } |
|---|
| 134 | --- /example --- |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | What, where, how? |
|---|
| 139 | ----------------- |
|---|
| 140 | Classes: |
|---|
| 141 | -> comments go inside *.h files |
|---|
| 142 | -> always include a brief AND detailed description |
|---|
| 143 | |
|---|
| 144 | Methods/Slots/ctor/dtor: |
|---|
| 145 | -> comments go inside *.cpp files |
|---|
| 146 | -> no brief, only detailed description |
|---|
| 147 | |
|---|
| 148 | Attributes: |
|---|
| 149 | -> comments go inside *.cpp OR *.h files |
|---|
| 150 | (put your comment in front of the declaration, normally |
|---|
| 151 | this will be in the header file) |
|---|
| 152 | -> a detailed description is sufficient |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | EXAMPLES: |
|---|
| 157 | --------- |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | Commenting a class: ( myclass.h ) |
|---|
| 162 | ------------------- |
|---|
| 163 | |
|---|
| 164 | /*! \brief Here a brief one-line description :) |
|---|
| 165 | * |
|---|
| 166 | * And here begins the detailed description of MyDocumentedClass. |
|---|
| 167 | * It consists of multiple lines and describes every important |
|---|
| 168 | * thing regarding this Class! |
|---|
| 169 | */ |
|---|
| 170 | class MyDocumentedClass (QWidget *parent, bool bFoo) |
|---|
| 171 | { |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | Commenting a Method/Slot/Constructor/Desctructor: ( myclass.cpp ) |
|---|
| 177 | ------------------------------------------------- |
|---|
| 178 | |
|---|
| 179 | /*! \brief Here a brief one-line description :) |
|---|
| 180 | * |
|---|
| 181 | * And here begins the detailed description of the slot ok() |
|---|
| 182 | * Every detailed description can be multiple lines long. |
|---|
| 183 | */ |
|---|
| 184 | void MyDocumentedClass::slot_okButtonPressed() |
|---|
| 185 | { |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | Commenting Attributes: ( myclass.cpp ) |
|---|
| 191 | ----------------------- |
|---|
| 192 | |
|---|
| 193 | /*! This QCheckBox indicates if we are cool or not */ |
|---|
| 194 | QCheckBox *chkAreWeCool; |
|---|
| 195 | /*! This QLineEdit holds a value which is the UIN of the owner */ |
|---|
| 196 | QLineEdit *nUin; |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | OK, THAT'S IT! |
|---|
| 200 | ============== |
|---|
| 201 | |
|---|
| 202 | Now close this doc and have |
|---|
| 203 | fun with the code :) |
|---|
| 204 | |
|---|
| 205 | Thomas Reitelbach |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | post scriptum: |
|---|
| 210 | I borrowed the CodingStyle readme from the linux kernel tree |
|---|
| 211 | while writing this document. Some parts may look similar. |
|---|
| 212 | A big "thank you" goes to the kernel tree people :) |
|---|
| 213 | |
|---|
| 214 | post post scriptum: |
|---|
| 215 | It is: |
|---|
| 216 | if (x) |
|---|
| 217 | { |
|---|
| 218 | // |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | And NOT: |
|---|
| 222 | if (x) { |
|---|
| 223 | // |
|---|
| 224 | } |
|---|