root/vidalia/trunk/HACKING

Revision 2976, 8.4 kB (checked in by edmanm, 4 days ago)

This one needed a better example.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1$Id$
2
3              Vidalia Coding and Repository Specification
4
50. Introduction
6 
7  This document is intended to loosely specify coding conventions followed in
8  Vidalia code, as well as conventions used in Vidalia's Subversion
9  repository.
10
111. Repository Organization
12
131.1. Subversion Location
14 
15  Vidalia's repository supports anonymous checkout. You can grab the most
16  recent revision of Vidalia's source code via:
17
18    svn co https://svn.vidalia-project.net/svn/vidalia/trunk/ vidalia
19
201.2 Directory Layout
21
22  The following are the current directories found in Vidalia's SVN repository
23  and a general decription of their intended contents:
24 
25  From https://svn.vidalia-project.net/svn/vidalia:
26
27     ./tags:
28
29        Snapshots of all Vidalia releases will be contained in a sub-directory
30        of ./tags, named according to the Vidalia version specification.
31        For example, ./tags/vidalia-0.0.1/ would contain the 0.0.1 release of
32        Vidalia.
33 
34     ./trunk:
35
36        Contains the main branch of Vidalia's source code.
37
38     ./trunk/doc:
39
40        Contains Vidalia's documentation, such as specifications and todo
41        lists.
42
43     ./trunk/src:
44
45        All Vidalia source code will be contained under this directory.
46
47     ./trunk/src/torcontrol:
48
49        Code in this directory implements Tor's control protocol. It also
50        handles things such as starting and stopping Tor and checking the
51        status of the Tor process.
52
53     ./trunk/src/vidalia:
54
55       This directory contains code that implements the GUI components of
56       Vidalia. Whenever possible and sane, each component should be placed in
57       an appropriately-named subdirectory of ./trunk/src/gui.
58
59    ./trunk/src/vidalia/res:
60
61       All GUI-related resource files, such as images, should go in this
62       directory. Images should be placed in sub-directories appropriate for
63       their image size. For example, 16x16 images would go in
64       ./trunk/src/vidalia/res/16x16/
65       
66    ./trunk/src/common:
67
68       If a source file doesn't belong in the previous directories, it should
69       go here. This directory will containg various utility functions, such
70       as date or time parsing, custom string manipulation functions, etc. If
71       a particular utility has multiple source files, they should all be
72       placed in a subdirectory. For example, if there were several source
73       files that implemented various string manipulation functions, they
74       could go in ./trunk/src/common/string.
75
762. Coding Conventions
77 
78  This section aims to provide a small overview of coding conventions used in
79  Vidalia, to keep the look of the code consistent between developers and
80  contributors. Since it would be impossible to specify all aspects of coding
81  here, common sense should be employed for things not specified below.
82
832.1. Naming Conventions
84
852.1.1. Source File Names
86 
87  C++ classes should be divided in to a <classname>.h file, containing the
88  class declarations, and a <classname>.cpp file containg the class
89  implementation. Each .cpp file should implement only one public class.
90
91  Source files that do not implement a C++ class should be named logically.
92  For example, threading code would go in thread.cpp and thread.h.
93 
94  Filenames should be all lower case to prevent potential cross-platform
95  compilation issues due to Windows being case insensitive as opposed to
96  nearly every OS being case sensitive.
97
982.1.2. Class Names
99
100  Class names should begin with a capital letter. If a name is a combination
101  of distinct words, each word should be capitalized. The purpose of the class
102  should be explained in Doxygen tags. Example:
103
104    /** A brief description of MyClass. */
105    /**
106     * Alternatively, here is a more detailed description of MyClass.
107     */
108    class MyClass
109    {
110    };
111
1122.1.3. Method Names
113 
114  Method names should begin with a lower case letter. If a method name is a
115  combination of distinct words, each word should be capitalized. Methods
116  should have descriptions of their purpose in Doxygen tags. Example:
117
118    /** Description of what someMethod does.
119     * \param foo The number of foo.
120     * \return the return value of someMethod.
121     */
122    int
123    MyClass::someMethod(int foo)
124    {
125    }
126   
127  Note that the method's return type is declared on a line by itself. Private
128  member function should NOT have an underscore prepended to their name.
129
1302.1.4. Variable Names
131
132  Variable names should follow a convention similar to method names. Variable
133  names should be descriptive if their purpose is non-obvious.
134
135  Variables that are members of a class should have a leading underscore to
136  distinguish them from local variables in a method. Member variables should
137  also have a description of their purpose in Doxygen tags. For example:
138
139  /** A brief description of MyClass */
140 
141  /**
142   * A more detailed description of MyClass.
143   */
144  class MyClass
145  {
146    private:
147      int _myVariable; /**< Description of what _myVariable is */
148  };
149 
1502.1.5. Ordering of Method and Member Variable Declarations
151
152  Class member method and variable declarations should be arranged according
153  to decreasing order of visibility.
154
155  class MyClass : public QObject
156  {
157    Q_OBJECT
158   
159    public:
160      /* Public enums */
161
162      /* Public methods */
163 
164    public slots:
165      /* Public slots */
166
167    signals:
168      /* Signals emitted by this class */
169   
170    protected:
171      /* Protected methods */
172
173      /* Protected member variables */
174
175    protected slots:
176      /* Protected slots */
177   
178    private:
179      /* Private methods */
180
181      /* Private member variables */
182   
183    private slots:
184      /* Private slots */
185  };
186
1872.1.6. Widget Names
188
189  Every widget declared in a Qt Designer .ui file must have a short three or
190  four letter prefix that describes the widget's type.
191
192       Widget Type           Prefix         Example
193       ------------------------------------------------------------
194       QCheckBox             chk            chkEnableFoo
195       QComboBox             cmbo           cmboNames
196       QFrame                frm            frmMain
197       QGroupBox             grp            grpAdvanced
198       QLabel                lbl            lblHeader
199       QLineEdit             line           lineAddress
200       QListView             lst            lstMessages
201       QProgressBar          pbar           pbarDownload
202       QPushButton           btn            btnClose
203       QRadioButton          rdo            rdoSomeOption
204       QSpinBox              spn            spnDial
205       QTableView            tbl            tblSpreadsheet
206       QTabWidget            tab            tabServerOptions
207       QToolButton           btn            btnExit
208       QTreeView             tree           treeFolders
209
210
2112.2. Comments
212
213  Comments should be standard C style comments. For example:
214
215    int fooCounter;  /* Comment about counting foo */
216
217  Multi-line comments should be formatted as:
218
219    /*
220     * This section of code is potentially confusing or ambiguous, so here is a
221     * long comment that takes up multiple lines.
222     */
223
2242.3. Indentation
225 
226  All source code should follow these conventions:
227 
228    1. Tabs should be 2 characters wide.
229    2. Your editor should be set to replace tabs with spaces.
230    3. Lines should be less than 80 characters wide whenever possible.
231
2322.4. Bracing
233
2342.4.1. Methods
235
236  Opening and closing braces for functions should be placed at column 1. For
237  example:
238
239     void
240     Foo::bar(void)
241     {
242     }
243
2442.4.2. Loops
245
246  Braces for loops should be formatted as follows:
247     
248     for (i = 0; i < 10; i++) {
249       /* Do something ten times */
250     }
251
2522.4.3. if-else Statements
253
254  The `else' portion of an if-else statement, if present, should begin on the
255  same line as the closing brace of the `if' portion.
256
257     if (foo == bar) {
258       /* Do something */
259     } else {
260       /* My foo doesn't equal bar */
261     }
262
263  Braces may be omitted if there is only one line of code to be executed if
264  the evaluated condition is true. For example, the following is permitted:
265
266    if (foo == bar)
267      return;
268
2692.5. Parentheses
270
271 
272  int value = someObject.someMethod(foo, bar, baz);
273
2742.6. Method Arguments
275
276  const-correctness should be enforced whenever possible. Objects passed as
277  arguments to a method should be passed by a const reference, as in the
278  following example:
279
280    void
281    SomeClass::someMethod(const OtherClass &oc)
282    {
283      /* Do something with oc */
284    }
285
2862.7. Other
287
288  Source files should end with a single blank line.
289
Note: See TracBrowser for help on using the browser.