summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/StyleConvention
blob: f4951d75e8912f3b4fa6564183c4d568551e365b (plain)
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
        Coding Style Convention
       -------------------------

This document describes the coding style convention
used in KPovModeler.

Author: Andreas Zehender <zehender@kde.org>
Date: 16 June 2001

If you edit existing files or create new ones, please follow this convention.
This ensures that the code is consistent and clear.

1) Indentation
--------------

- Use 3 spaces as basic offset. Do not use tabs for indentation.
- Do not indent access keywords (public, protected, private) as
  well as signal/slot keywords.
- Do not indent braces.
- Put braces in separate lines.
- Indent case statements.

Example:
class abcd
{
public:
   void someMethod( );
};

void abcd::someMethod( )
{
   if( 1 == 2 )
   {
   }
   else
   {
      switch( x )
      {
         case 1:
            y = 2;
            break;
         default:
            y = -2;
      }
   }
}


2) Spacing
----------

Use many spaces.
Use it
- before and after brackets
- before and after operators
- after commas

Examples:

a = someMethod( ); // Notice the space between the brackets!
b = anotherMethod( ( a + b ) / 2, 3 ) || 23456;
if( ( a == 2 ) && !b )


3) Type Modifiers (Pointers and References)
-------------------------------------------

Put type modifiers behind the type, not before the variable name.

Example:

const QString& type;
PMObject* obj;


4) Names
--------

Variables:
----------
Member variables begin with "m_".
Static variables begin with "s_".
Member pointers begin with "m_p".

All variables begin with a lower case (member variables after the "m_").
Use upper case character to separate different words.

Examples:

class abcd
{
   int m_firstMember;
   char* m_pFirstMember;
   static const char* s_pAStaticPointerToConstCharThatMeansItIsAString;
};

void abcd::efgh( )
{
   int aLocalVariable;
}

Classes:
--------
All classes start with "PM" and a upper case character.

Methods:
--------
All methods start with a lower case character.

Set methods begin with "set".
Get methods do NOT begin with "get".

Examples:

int PMSPhere::centre( ) const;
void PMSphere::setCentre( );

5) KDoc Comments
----------------

Use KDoc comments to document classes.

Don't add a description if you just overload a virtual function
that doesn't add some functionality.

Example:

/** Returns the internal object name (not i18n'ed) */
virtual PMObject::className( ) const;

/** */
virtual PMSphere::className( ) const;

KDoc will then generate the following output:

<documentation>
PMObject*  newObject ( ) 

[const virtual]

Reimplemented from PMObject.
</documentation>


6) Long Lines
--------------
Try to use only 80 characters per line.


7) Sample .emacs File
---------------------

Here is a sample .emacs file. It is a mix of several files, so some
things are set multiple times. But it works :-)

<.emacs>
(defconst my-c-style
  '((c-tab-always-indent           . t)
    (c-comment-only-line-offset    . 0)
    (c-hanging-braces-alist        . ((substatement-open after)
                                      (brace-list-open)))
    (c-hanging-colons-alist        . ((member-init-intro before)
                                      (inher-intro)
                                      (case-label after)
                                      (label after)
                                      (access-label after)))
    (c-cleanup-list                . (scope-operator
                                      empty-defun-braces
                                      defun-close-semi))
    (c-offsets-alist               . ((arglist-close     . c-lineup-arglist)
                                      (substatement-open . 0)
                                      (case-label        . +)
                                      (block-open        . 0)
                                      (knr-argdecl-intro . -)
				      (inline-open       . 0)))
    (c-echo-syntactic-information-p . t)
    )
  "My C Programming Style")
  
;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
  ;; add my personal style and set it for the current buffer
  (c-add-style "PERSONAL" my-c-style t)
  ;; offset customizations not in my-c-style
  (c-set-offset 'member-init-intro '++)
  ;; other customizations
  (setq tab-width 8
        ;; this will make sure spaces are used instead of tabs
        indent-tabs-mode nil)
  (setq c-basic-offset 3)
  ;; we like auto-newline and hungry-delete
  (c-toggle-hungry-state 1)
  ;; keybindings for C, C++, and Objective-C.  We can put these in
  ;; c-mode-map because c++-mode-map and objc-mode-map inherit it
  (define-key c-mode-map [f9] 'compile)
  (define-key c-mode-map [return] 'newline-and-indent)
  (define-key c++-mode-map [f9] 'compile)
  (define-key c++-mode-map [return] 'newline-and-indent)
  (define-key java-mode-map [f9] 'compile)
  (define-key java-mode-map [return] 'newline-and-indent)
  (load-library "vc")
  
  ;;for QT
  (setq c-C++-access-key "\\<\\(Q_SIGNALS\\|public\\|protected\\|private
  \\|public Q_SLOTS\\|protected Q_SLOTS\\|private Q_SLOTS\\)\\>[ \t]*:")
  ;; modify the colour of Q_SLOTS to match public, private, etc ...
  (font-lock-add-keywords 'c++-mode
  '(("\\<\\(Q_SLOTS\\|Q_SIGNALS\\)\\>" . font-lock-type-face)))
  ;; make new font for rest of qt keywords
  (make-face 'qt-keywords-face)
  (set-face-foreground 'qt-keywords-face "green")
  ;; qt keywords
  (font-lock-add-keywords 'c++-mode
  '(("\\<Q_OBJECT\\>" . 'qt-keywords-face)))
  (font-lock-add-keywords 'c++-mode
  '(("\\<SIGNAL\\|SLOT\\>" . 'qt-keywords-face)))
  (font-lock-add-keywords 'c++-mode
  '(("\\<Q[A-Z][A-Za-z]*" . 'qt-keywords-face)))
  )
   
(setq auto-mode-alist
         (append '(("\\.h$"    . c++-mode)) auto-mode-alist))

</.emacs>