1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
|
2 |
<!-- saved from url=(0043)cppstyle.html -->
|
3 |
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
4 |
xmlns:o="urn:schemas-microsoft-com:office:office"
|
5 |
xmlns:w="urn:schemas-microsoft-com:office:word"
|
6 |
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
|
7 |
xmlns="http://www.w3.org/TR/REC-html40">
|
8 |
|
9 |
<head>
|
10 |
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
|
11 |
<meta name=ProgId content=Word.Document>
|
12 |
<meta name=Generator content="Microsoft Word 10">
|
13 |
<meta name=Originator content="Microsoft Word 10">
|
14 |
<link rel=File-List href="OpenMD-1.0%20C++%20coding_style.files/filelist.xml">
|
15 |
<link rel=Edit-Time-Data
|
16 |
href="OpenMD-1.0%20C++%20coding_style.files/editdata.mso">
|
17 |
<!--[if !mso]>
|
18 |
<style>
|
19 |
v\:* {behavior:url(#default#VML);}
|
20 |
o\:* {behavior:url(#default#VML);}
|
21 |
w\:* {behavior:url(#default#VML);}
|
22 |
.shape {behavior:url(#default#VML);}
|
23 |
</style>
|
24 |
<![endif]-->
|
25 |
<title>C++ Programming Style Guidelines</title>
|
26 |
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
|
27 |
name="City"/>
|
28 |
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
|
29 |
name="place"/>
|
30 |
<!--[if gte mso 9]><xml>
|
31 |
<o:DocumentProperties>
|
32 |
<o:Author>tim</o:Author>
|
33 |
<o:LastAuthor>Teng</o:LastAuthor>
|
34 |
<o:Revision>14</o:Revision>
|
35 |
<o:TotalTime>97</o:TotalTime>
|
36 |
<o:Created>2004-09-17T20:46:00Z</o:Created>
|
37 |
<o:LastSaved>2004-09-18T03:55:00Z</o:LastSaved>
|
38 |
<o:Pages>7</o:Pages>
|
39 |
<o:Words>6327</o:Words>
|
40 |
<o:Characters>36068</o:Characters>
|
41 |
<o:Company>University of Notre Dame</o:Company>
|
42 |
<o:Lines>300</o:Lines>
|
43 |
<o:Paragraphs>84</o:Paragraphs>
|
44 |
<o:CharactersWithSpaces>42311</o:CharactersWithSpaces>
|
45 |
<o:Version>10.3501</o:Version>
|
46 |
</o:DocumentProperties>
|
47 |
</xml><![endif]--><!--[if gte mso 9]><xml>
|
48 |
<w:WordDocument>
|
49 |
<w:GrammarState>Clean</w:GrammarState>
|
50 |
<w:Compatibility>
|
51 |
<w:UseFELayout/>
|
52 |
</w:Compatibility>
|
53 |
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
54 |
</w:WordDocument>
|
55 |
</xml><![endif]--><!--[if !mso]><object
|
56 |
classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
|
57 |
<style>
|
58 |
st1\:*{behavior:url(#ieooui) }
|
59 |
</style>
|
60 |
<![endif]-->
|
61 |
<link rel=Stylesheet type="text/css" media=all
|
62 |
href="style.css">
|
63 |
<style>
|
64 |
<!--
|
65 |
/* Font Definitions */
|
66 |
@font-face
|
67 |
{font-family:SimSun;
|
68 |
panose-1:2 1 6 0 3 1 1 1 1 1;
|
69 |
mso-font-alt:SimSun;
|
70 |
mso-font-charset:134;
|
71 |
mso-generic-font-family:auto;
|
72 |
mso-font-pitch:variable;
|
73 |
mso-font-signature:3 135135232 16 0 262145 0;}
|
74 |
@font-face
|
75 |
{font-family:fixed;
|
76 |
panose-1:0 0 0 0 0 0 0 0 0 0;
|
77 |
mso-font-alt:"Times New Roman";
|
78 |
mso-font-charset:0;
|
79 |
mso-generic-font-family:roman;
|
80 |
mso-font-format:other;
|
81 |
mso-font-pitch:auto;
|
82 |
mso-font-signature:0 0 0 0 0 0;}
|
83 |
@font-face
|
84 |
{font-family:SimSun;
|
85 |
panose-1:2 1 6 0 3 1 1 1 1 1;
|
86 |
mso-font-charset:134;
|
87 |
mso-generic-font-family:auto;
|
88 |
mso-font-pitch:variable;
|
89 |
mso-font-signature:3 135135232 16 0 262145 0;}
|
90 |
/* Style Definitions */
|
91 |
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
92 |
{mso-style-parent:"";
|
93 |
margin:0cm;
|
94 |
margin-bottom:.0001pt;
|
95 |
mso-pagination:widow-orphan;
|
96 |
font-size:12.0pt;
|
97 |
font-family:"Times New Roman";
|
98 |
mso-fareast-font-family:SimSun;}
|
99 |
h1
|
100 |
{mso-margin-top-alt:auto;
|
101 |
margin-right:0cm;
|
102 |
mso-margin-bottom-alt:auto;
|
103 |
margin-left:0cm;
|
104 |
mso-pagination:widow-orphan;
|
105 |
mso-outline-level:1;
|
106 |
font-size:12.0pt;
|
107 |
font-weight:bold;}
|
108 |
h2
|
109 |
{mso-margin-top-alt:auto;
|
110 |
margin-right:0cm;
|
111 |
mso-margin-bottom-alt:auto;
|
112 |
margin-left:0cm;
|
113 |
mso-pagination:widow-orphan;
|
114 |
mso-outline-level:2;
|
115 |
font-size:10.0pt;
|
116 |
font-weight:bold;}
|
117 |
h3
|
118 |
{mso-margin-top-alt:auto;
|
119 |
margin-right:0cm;
|
120 |
mso-margin-bottom-alt:auto;
|
121 |
margin-left:0cm;
|
122 |
mso-pagination:widow-orphan;
|
123 |
mso-outline-level:3;
|
124 |
font-size:10.0pt;
|
125 |
font-weight:bold;}
|
126 |
h4
|
127 |
{mso-margin-top-alt:auto;
|
128 |
margin-right:0cm;
|
129 |
mso-margin-bottom-alt:auto;
|
130 |
margin-left:0cm;
|
131 |
mso-pagination:widow-orphan;
|
132 |
mso-outline-level:4;
|
133 |
font-size:10.0pt;
|
134 |
font-weight:bold;}
|
135 |
a:link, span.MsoHyperlink
|
136 |
{mso-ansi-font-size:10.0pt;
|
137 |
mso-bidi-font-size:10.0pt;
|
138 |
font-family:Arial;
|
139 |
mso-ascii-font-family:Arial;
|
140 |
mso-hansi-font-family:Arial;
|
141 |
mso-bidi-font-family:Arial;
|
142 |
color:blue;
|
143 |
text-decoration:underline;
|
144 |
text-underline:single;}
|
145 |
a:visited, span.MsoHyperlinkFollowed
|
146 |
{mso-ansi-font-size:10.0pt;
|
147 |
mso-bidi-font-size:10.0pt;
|
148 |
font-family:Arial;
|
149 |
mso-ascii-font-family:Arial;
|
150 |
mso-hansi-font-family:Arial;
|
151 |
mso-bidi-font-family:Arial;
|
152 |
color:blue;
|
153 |
text-decoration:underline;
|
154 |
text-underline:single;}
|
155 |
p
|
156 |
{mso-margin-top-alt:auto;
|
157 |
margin-right:0cm;
|
158 |
mso-margin-bottom-alt:auto;
|
159 |
margin-left:0cm;
|
160 |
mso-pagination:widow-orphan;
|
161 |
font-size:10.0pt;
|
162 |
mso-fareast-font-family:SimSun;}
|
163 |
code
|
164 |
{mso-ansi-font-size:9.0pt;
|
165 |
mso-bidi-font-size:9.0pt;
|
166 |
mso-fareast-font-family:SimSun;
|
167 |
mso-bidi-font-family:"Courier New";}
|
168 |
pre
|
169 |
{margin-top:0cm;
|
170 |
margin-right:0cm;
|
171 |
margin-bottom:0cm;
|
172 |
margin-left:20.0pt;
|
173 |
margin-bottom:.0001pt;
|
174 |
mso-pagination:widow-orphan;
|
175 |
tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;
|
176 |
font-size:9.0pt;
|
177 |
mso-fareast-font-family:SimSun;
|
178 |
mso-bidi-font-family:"Courier New";}
|
179 |
tt
|
180 |
{mso-ansi-font-size:12.0pt;
|
181 |
mso-bidi-font-size:12.0pt;
|
182 |
mso-fareast-font-family:SimSun;
|
183 |
mso-bidi-font-family:"Courier New";}
|
184 |
p.comment, li.comment, div.comment
|
185 |
{mso-style-name:comment;
|
186 |
mso-margin-top-alt:auto;
|
187 |
margin-right:0cm;
|
188 |
mso-margin-bottom-alt:auto;
|
189 |
margin-left:0cm;
|
190 |
mso-pagination:widow-orphan;
|
191 |
font-size:10.0pt;
|
192 |
mso-fareast-font-family:SimSun;}
|
193 |
p.normal, li.normal, div.normal
|
194 |
{mso-style-name:normal;
|
195 |
mso-margin-top-alt:auto;
|
196 |
margin-right:0cm;
|
197 |
mso-margin-bottom-alt:auto;
|
198 |
margin-left:0cm;
|
199 |
mso-pagination:widow-orphan;
|
200 |
font-size:10.0pt;
|
201 |
mso-fareast-font-family:SimSun;}
|
202 |
p.menu, li.menu, div.menu
|
203 |
{mso-style-name:menu;
|
204 |
mso-margin-top-alt:auto;
|
205 |
margin-right:0cm;
|
206 |
mso-margin-bottom-alt:auto;
|
207 |
margin-left:0cm;
|
208 |
mso-pagination:widow-orphan;
|
209 |
background:#004477;
|
210 |
font-size:10.0pt;
|
211 |
mso-fareast-font-family:SimSun;}
|
212 |
p.title, li.title, div.title
|
213 |
{mso-style-name:title;
|
214 |
mso-margin-top-alt:auto;
|
215 |
margin-right:0cm;
|
216 |
mso-margin-bottom-alt:auto;
|
217 |
margin-left:0cm;
|
218 |
text-align:right;
|
219 |
mso-pagination:widow-orphan;
|
220 |
background:#004477;
|
221 |
font-size:24.0pt;
|
222 |
mso-fareast-font-family:SimSun;
|
223 |
font-weight:bold;}
|
224 |
p.smalltitle, li.smalltitle, div.smalltitle
|
225 |
{mso-style-name:smalltitle;
|
226 |
mso-margin-top-alt:auto;
|
227 |
margin-right:0cm;
|
228 |
mso-margin-bottom-alt:auto;
|
229 |
margin-left:0cm;
|
230 |
text-align:right;
|
231 |
mso-pagination:widow-orphan;
|
232 |
background:#004477;
|
233 |
font-size:18.0pt;
|
234 |
mso-fareast-font-family:SimSun;
|
235 |
font-weight:bold;
|
236 |
font-style:italic;}
|
237 |
p.footnote, li.footnote, div.footnote
|
238 |
{mso-style-name:footnote;
|
239 |
mso-margin-top-alt:auto;
|
240 |
margin-right:0cm;
|
241 |
mso-margin-bottom-alt:auto;
|
242 |
margin-left:0cm;
|
243 |
mso-pagination:widow-orphan;
|
244 |
font-size:8.0pt;
|
245 |
mso-fareast-font-family:SimSun;}
|
246 |
p.address, li.address, div.address
|
247 |
{mso-style-name:address;
|
248 |
mso-margin-top-alt:auto;
|
249 |
margin-right:0cm;
|
250 |
mso-margin-bottom-alt:auto;
|
251 |
margin-left:0cm;
|
252 |
mso-pagination:widow-orphan;
|
253 |
font-size:12.0pt;
|
254 |
mso-fareast-font-family:SimSun;
|
255 |
font-weight:bold;}
|
256 |
p.access, li.access, div.access
|
257 |
{mso-style-name:access;
|
258 |
mso-margin-top-alt:auto;
|
259 |
margin-right:0cm;
|
260 |
mso-margin-bottom-alt:auto;
|
261 |
margin-left:0cm;
|
262 |
mso-pagination:widow-orphan;
|
263 |
background:#990000;
|
264 |
font-size:8.0pt;
|
265 |
mso-fareast-font-family:SimSun;}
|
266 |
p.noaccess, li.noaccess, div.noaccess
|
267 |
{mso-style-name:noaccess;
|
268 |
mso-margin-top-alt:auto;
|
269 |
margin-right:0cm;
|
270 |
mso-margin-bottom-alt:auto;
|
271 |
margin-left:0cm;
|
272 |
mso-pagination:widow-orphan;
|
273 |
background:#CCBBBB;
|
274 |
font-size:8.0pt;
|
275 |
mso-fareast-font-family:SimSun;}
|
276 |
p.legend, li.legend, div.legend
|
277 |
{mso-style-name:legend;
|
278 |
mso-margin-top-alt:auto;
|
279 |
margin-right:0cm;
|
280 |
mso-margin-bottom-alt:auto;
|
281 |
margin-left:0cm;
|
282 |
mso-pagination:widow-orphan;
|
283 |
background:#CCAAAA;
|
284 |
font-size:8.0pt;
|
285 |
mso-fareast-font-family:SimSun;}
|
286 |
p.trendentry, li.trendentry, div.trendentry
|
287 |
{mso-style-name:trendentry;
|
288 |
mso-margin-top-alt:auto;
|
289 |
margin-right:0cm;
|
290 |
mso-margin-bottom-alt:auto;
|
291 |
margin-left:0cm;
|
292 |
mso-pagination:widow-orphan;
|
293 |
font-size:12.0pt;
|
294 |
mso-fareast-font-family:SimSun;}
|
295 |
p.navigator, li.navigator, div.navigator
|
296 |
{mso-style-name:navigator;
|
297 |
mso-margin-top-alt:auto;
|
298 |
margin-right:0cm;
|
299 |
mso-margin-bottom-alt:auto;
|
300 |
margin-left:0cm;
|
301 |
mso-pagination:widow-orphan;
|
302 |
background:#CCBBBB;
|
303 |
font-size:10.0pt;
|
304 |
mso-fareast-font-family:SimSun;
|
305 |
font-weight:bold;}
|
306 |
p.recom, li.recom, div.recom
|
307 |
{mso-style-name:recom;
|
308 |
mso-margin-top-alt:auto;
|
309 |
margin-right:0cm;
|
310 |
mso-margin-bottom-alt:auto;
|
311 |
margin-left:0cm;
|
312 |
mso-pagination:widow-orphan;
|
313 |
background:#BBCCEE;
|
314 |
font-size:10.0pt;
|
315 |
mso-fareast-font-family:SimSun;
|
316 |
font-weight:bold;}
|
317 |
p.practice, li.practice, div.practice
|
318 |
{mso-style-name:practice;
|
319 |
mso-margin-top-alt:auto;
|
320 |
margin-right:0cm;
|
321 |
mso-margin-bottom-alt:auto;
|
322 |
margin-left:0cm;
|
323 |
mso-pagination:widow-orphan;
|
324 |
background:#BBCCEE;
|
325 |
font-size:10.0pt;
|
326 |
mso-fareast-font-family:SimSun;
|
327 |
font-weight:bold;}
|
328 |
p.rationale, li.rationale, div.rationale
|
329 |
{mso-style-name:rationale;
|
330 |
mso-margin-top-alt:auto;
|
331 |
margin-right:0cm;
|
332 |
mso-margin-bottom-alt:auto;
|
333 |
margin-left:0cm;
|
334 |
mso-pagination:widow-orphan;
|
335 |
font-size:9.0pt;
|
336 |
mso-fareast-font-family:SimSun;}
|
337 |
p.cvtitle, li.cvtitle, div.cvtitle
|
338 |
{mso-style-name:cvtitle;
|
339 |
mso-margin-top-alt:auto;
|
340 |
margin-right:0cm;
|
341 |
mso-margin-bottom-alt:auto;
|
342 |
margin-left:0cm;
|
343 |
text-align:center;
|
344 |
mso-pagination:widow-orphan;
|
345 |
background:#004477;
|
346 |
font-size:24.0pt;
|
347 |
mso-fareast-font-family:SimSun;
|
348 |
font-weight:bold;}
|
349 |
p.cvsmalltitle, li.cvsmalltitle, div.cvsmalltitle
|
350 |
{mso-style-name:cvsmalltitle;
|
351 |
mso-margin-top-alt:auto;
|
352 |
margin-right:0cm;
|
353 |
mso-margin-bottom-alt:auto;
|
354 |
margin-left:0cm;
|
355 |
mso-pagination:widow-orphan;
|
356 |
background:#004477;
|
357 |
font-size:18.0pt;
|
358 |
mso-fareast-font-family:SimSun;}
|
359 |
p.cvprompt, li.cvprompt, div.cvprompt
|
360 |
{mso-style-name:cvprompt;
|
361 |
mso-margin-top-alt:auto;
|
362 |
margin-right:0cm;
|
363 |
mso-margin-bottom-alt:auto;
|
364 |
margin-left:0cm;
|
365 |
mso-pagination:widow-orphan;
|
366 |
font-size:10.0pt;
|
367 |
mso-fareast-font-family:SimSun;
|
368 |
font-weight:bold;}
|
369 |
p.warning, li.warning, div.warning
|
370 |
{mso-style-name:warning;
|
371 |
mso-margin-top-alt:auto;
|
372 |
margin-right:0cm;
|
373 |
mso-margin-bottom-alt:auto;
|
374 |
margin-left:0cm;
|
375 |
mso-pagination:widow-orphan;
|
376 |
background:yellow;
|
377 |
font-size:10.0pt;
|
378 |
mso-fareast-font-family:SimSun;}
|
379 |
p.copyright, li.copyright, div.copyright
|
380 |
{mso-style-name:copyright;
|
381 |
mso-margin-top-alt:auto;
|
382 |
margin-right:0cm;
|
383 |
mso-margin-bottom-alt:auto;
|
384 |
margin-left:0cm;
|
385 |
mso-pagination:widow-orphan;
|
386 |
font-size:7.0pt;
|
387 |
mso-fareast-font-family:SimSun;}
|
388 |
p.small, li.small, div.small
|
389 |
{mso-style-name:small;
|
390 |
mso-margin-top-alt:auto;
|
391 |
margin-right:0cm;
|
392 |
mso-margin-bottom-alt:auto;
|
393 |
margin-left:0cm;
|
394 |
mso-pagination:widow-orphan;
|
395 |
font-size:8.0pt;
|
396 |
mso-fareast-font-family:SimSun;}
|
397 |
span.GramE
|
398 |
{mso-style-name:"";
|
399 |
mso-gram-e:yes;}
|
400 |
@page Section1
|
401 |
{size:612.0pt 792.0pt;
|
402 |
margin:72.0pt 90.0pt 72.0pt 90.0pt;
|
403 |
mso-header-margin:36.0pt;
|
404 |
mso-footer-margin:36.0pt;
|
405 |
mso-paper-source:0;}
|
406 |
div.Section1
|
407 |
{page:Section1;}
|
408 |
/* List Definitions */
|
409 |
@list l0
|
410 |
{mso-list-id:891768119;
|
411 |
mso-list-template-ids:317624060;}
|
412 |
@list l0:level1
|
413 |
{mso-level-number-format:bullet;
|
414 |
mso-level-text:\F0B7;
|
415 |
mso-level-tab-stop:36.0pt;
|
416 |
mso-level-number-position:left;
|
417 |
text-indent:-18.0pt;
|
418 |
mso-ansi-font-size:10.0pt;
|
419 |
font-family:Symbol;}
|
420 |
@list l0:level2
|
421 |
{mso-level-number-format:bullet;
|
422 |
mso-level-text:o;
|
423 |
mso-level-tab-stop:72.0pt;
|
424 |
mso-level-number-position:left;
|
425 |
text-indent:-18.0pt;
|
426 |
mso-ansi-font-size:10.0pt;
|
427 |
font-family:"Courier New";
|
428 |
mso-bidi-font-family:"Times New Roman";}
|
429 |
@list l0:level3
|
430 |
{mso-level-tab-stop:108.0pt;
|
431 |
mso-level-number-position:left;
|
432 |
text-indent:-18.0pt;}
|
433 |
@list l0:level4
|
434 |
{mso-level-tab-stop:144.0pt;
|
435 |
mso-level-number-position:left;
|
436 |
text-indent:-18.0pt;}
|
437 |
@list l0:level5
|
438 |
{mso-level-tab-stop:180.0pt;
|
439 |
mso-level-number-position:left;
|
440 |
text-indent:-18.0pt;}
|
441 |
@list l0:level6
|
442 |
{mso-level-tab-stop:216.0pt;
|
443 |
mso-level-number-position:left;
|
444 |
text-indent:-18.0pt;}
|
445 |
@list l0:level7
|
446 |
{mso-level-tab-stop:252.0pt;
|
447 |
mso-level-number-position:left;
|
448 |
text-indent:-18.0pt;}
|
449 |
@list l0:level8
|
450 |
{mso-level-tab-stop:288.0pt;
|
451 |
mso-level-number-position:left;
|
452 |
text-indent:-18.0pt;}
|
453 |
@list l0:level9
|
454 |
{mso-level-tab-stop:324.0pt;
|
455 |
mso-level-number-position:left;
|
456 |
text-indent:-18.0pt;}
|
457 |
@list l1
|
458 |
{mso-list-id:923807935;
|
459 |
mso-list-template-ids:476496218;}
|
460 |
@list l1:level1
|
461 |
{mso-level-number-format:bullet;
|
462 |
mso-level-text:\F0B7;
|
463 |
mso-level-tab-stop:36.0pt;
|
464 |
mso-level-number-position:left;
|
465 |
text-indent:-18.0pt;
|
466 |
mso-ansi-font-size:10.0pt;
|
467 |
font-family:Symbol;}
|
468 |
@list l1:level2
|
469 |
{mso-level-number-format:bullet;
|
470 |
mso-level-text:o;
|
471 |
mso-level-tab-stop:72.0pt;
|
472 |
mso-level-number-position:left;
|
473 |
text-indent:-18.0pt;
|
474 |
mso-ansi-font-size:10.0pt;
|
475 |
font-family:"Courier New";
|
476 |
mso-bidi-font-family:"Times New Roman";}
|
477 |
@list l2
|
478 |
{mso-list-id:1731999742;
|
479 |
mso-list-template-ids:-1833422612;}
|
480 |
@list l2:level1
|
481 |
{mso-level-number-format:bullet;
|
482 |
mso-level-text:\F0B7;
|
483 |
mso-level-tab-stop:36.0pt;
|
484 |
mso-level-number-position:left;
|
485 |
text-indent:-18.0pt;
|
486 |
mso-ansi-font-size:10.0pt;
|
487 |
font-family:Symbol;}
|
488 |
@list l2:level2
|
489 |
{mso-level-tab-stop:72.0pt;
|
490 |
mso-level-number-position:left;
|
491 |
text-indent:-18.0pt;}
|
492 |
@list l2:level3
|
493 |
{mso-level-tab-stop:108.0pt;
|
494 |
mso-level-number-position:left;
|
495 |
text-indent:-18.0pt;}
|
496 |
@list l2:level4
|
497 |
{mso-level-tab-stop:144.0pt;
|
498 |
mso-level-number-position:left;
|
499 |
text-indent:-18.0pt;}
|
500 |
@list l2:level5
|
501 |
{mso-level-tab-stop:180.0pt;
|
502 |
mso-level-number-position:left;
|
503 |
text-indent:-18.0pt;}
|
504 |
@list l2:level6
|
505 |
{mso-level-tab-stop:216.0pt;
|
506 |
mso-level-number-position:left;
|
507 |
text-indent:-18.0pt;}
|
508 |
@list l2:level7
|
509 |
{mso-level-tab-stop:252.0pt;
|
510 |
mso-level-number-position:left;
|
511 |
text-indent:-18.0pt;}
|
512 |
@list l2:level8
|
513 |
{mso-level-tab-stop:288.0pt;
|
514 |
mso-level-number-position:left;
|
515 |
text-indent:-18.0pt;}
|
516 |
@list l2:level9
|
517 |
{mso-level-tab-stop:324.0pt;
|
518 |
mso-level-number-position:left;
|
519 |
text-indent:-18.0pt;}
|
520 |
@list l3
|
521 |
{mso-list-id:2136366238;
|
522 |
mso-list-template-ids:-1152741894;}
|
523 |
@list l3:level1
|
524 |
{mso-level-number-format:bullet;
|
525 |
mso-level-text:\F0B7;
|
526 |
mso-level-tab-stop:36.0pt;
|
527 |
mso-level-number-position:left;
|
528 |
text-indent:-18.0pt;
|
529 |
mso-ansi-font-size:10.0pt;
|
530 |
font-family:Symbol;}
|
531 |
ol
|
532 |
{margin-bottom:0cm;}
|
533 |
ul
|
534 |
{margin-bottom:0cm;}
|
535 |
.style1 {font-size: 10pt}
|
536 |
.style4 {font-family: fixed}
|
537 |
.style5 {font-size: 10}
|
538 |
.style6 {font-family: fixed; font-size: 10; }
|
539 |
.style7 {font-size: 12pt}
|
540 |
.style10 {font-size: 10.0pt}
|
541 |
.style12 {
|
542 |
font-family: Arial, Helvetica, sans-serif;
|
543 |
font-weight: bold;
|
544 |
}
|
545 |
.style13 {font-size: 7.5pt}
|
546 |
-->
|
547 |
</style>
|
548 |
<!--[if gte mso 10]>
|
549 |
<style>
|
550 |
/* Style Definitions */
|
551 |
table.MsoNormalTable
|
552 |
{mso-style-name:\666E\901A\8868\683C;
|
553 |
mso-tstyle-rowband-size:0;
|
554 |
mso-tstyle-colband-size:0;
|
555 |
mso-style-noshow:yes;
|
556 |
mso-style-parent:"";
|
557 |
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
558 |
mso-para-margin:0cm;
|
559 |
mso-para-margin-bottom:.0001pt;
|
560 |
mso-pagination:widow-orphan;
|
561 |
font-size:10.0pt;
|
562 |
font-family:"Times New Roman";
|
563 |
mso-fareast-font-family:"Times New Roman";}
|
564 |
table.TableNormal
|
565 |
{mso-style-name:"Table Normal";
|
566 |
mso-tstyle-rowband-size:0;
|
567 |
mso-tstyle-colband-size:0;
|
568 |
mso-style-noshow:yes;
|
569 |
mso-style-parent:"";
|
570 |
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
571 |
mso-para-margin:0cm;
|
572 |
mso-para-margin-bottom:.0001pt;
|
573 |
mso-pagination:widow-orphan;
|
574 |
font-size:10.0pt;
|
575 |
font-family:"Times New Roman";}
|
576 |
</style>
|
577 |
<![endif]-->
|
578 |
<meta content="Geotechnical Software Services" name=Author>
|
579 |
<meta
|
580 |
content="c++, c, programming, code, style, guideline, guidelines, recommendation, recommendations, layout, standard, conventions, standardization, naming, names, indentation, block, readability, maintainability, mixed case, suffix, prefix, statement, statements, conditional, white space, align, alignment comments, code complete, steve mcconnel, geosoft, geotechnical, software, services, stavanger, norway"
|
581 |
name=Keywords>
|
582 |
<meta
|
583 |
content="C++ Programming Style Guidelines. GeoSoft's 70+ style rules for C/C++ developers including naming conventions, code layout, commenting and more."
|
584 |
name=Description>
|
585 |
<!--[if gte mso 9]><xml>
|
586 |
<o:shapedefaults v:ext="edit" spidmax="1027"/>
|
587 |
</xml><![endif]--><!--[if gte mso 9]><xml>
|
588 |
<o:shapelayout v:ext="edit">
|
589 |
<o:idmap v:ext="edit" data="1"/>
|
590 |
</o:shapelayout></xml><![endif]-->
|
591 |
</head>
|
592 |
|
593 |
<body lang=ZH-CN link=blue vlink=blue style='tab-interval:36.0pt'>
|
594 |
|
595 |
<div class=Section1>
|
596 |
|
597 |
<table class=TableNormal border=0 cellspacing=0 cellpadding=0 style='mso-cellspacing:
|
598 |
0cm;mso-padding-alt:6.0pt 6.0pt 6.0pt 6.0pt'>
|
599 |
<tr style='mso-yfti-irow:0'>
|
600 |
<!--
|
601 |
*******************************************************************************
|
602 |
Document content on right hand side
|
603 |
*******************************************************************************
|
604 |
-->
|
605 |
<td style='padding:6.0pt 6.0pt 6.0pt 6.0pt'>
|
606 |
<h1 align=center style='text-align:center'><span lang=EN-US>C++ Programming
|
607 |
Style Guidelines <span class=GramE>for</span> OpenMD-1.0</span></h1>
|
608 |
<p align=center style='text-align:center'> <em>Version 1.0, September 2004 </em></p>
|
609 |
<p align=center style='text-align:center'><em><a href="http://www.openmd.net">OpenMD Developement Team</a></em></p> <p align=center style='text-align:center'><em>Department of Chemistry & Biochemistry</em></p>
|
610 |
<p align=center style='text-align:center; font-style: italic;'>University of Notre Dame</p>
|
611 |
<p align=center style='text-align:center; font-style: italic;'>Notre Dame, IN 46556</p>
|
612 |
<p align=center style='text-align:center; font-style: italic;'> The original document is available at <a href="http://geosoft.no/development/cppstyle.html">http://geosoft.no/development/cppstyle.html </a> </p>
|
613 |
<div class=MsoNormal align=center style='text-align:center'><span lang=EN-US
|
614 |
style='font-size:10.0pt;font-family:Arial'>
|
615 |
<hr size=3 width="100%" align=center>
|
616 |
</span></div>
|
617 |
<h2><span lang=EN-US>Table of Content</span></h2>
|
618 |
<ul type=disc>
|
619 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
620 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
621 |
style='font-size:10.0pt;font-family:Arial'><a
|
622 |
href="cppstyle.html#introduction">1
|
623 |
Introduction</a> <o:p></o:p></span></li>
|
624 |
<ul type=circle>
|
625 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
626 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
627 |
style='font-size:10.0pt;font-family:Arial'><a
|
628 |
href="cppstyle.html#Layout_of_the_Recommendations">1.1
|
629 |
Layout of the Recommendations</a> <o:p></o:p></span></li>
|
630 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
631 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
632 |
style='font-size:10.0pt;font-family:Arial'><a
|
633 |
href="cppstyle.html#Recommendation">1.2
|
634 |
Recommendations Importance</a> <o:p></o:p></span></li>
|
635 |
</ul>
|
636 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
637 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
638 |
style='font-size:10.0pt;font-family:Arial'><a
|
639 |
href="cppstyle.html#General_Recomendations">2
|
640 |
General Recommendations</a> <o:p></o:p></span></li>
|
641 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
642 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
643 |
style='font-size:10.0pt;font-family:Arial'><a
|
644 |
href="cppstyle.html#Naming_Conventions">3
|
645 |
Naming Conventions</a> <o:p></o:p></span></li>
|
646 |
<ul type=circle>
|
647 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
648 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
649 |
style='font-size:10.0pt;font-family:Arial'><a
|
650 |
href="cppstyle.html#General">3.1 General</a>
|
651 |
<o:p></o:p></span></li>
|
652 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
653 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
654 |
style='font-size:10.0pt;font-family:Arial'><a
|
655 |
href="cppstyle.html#Specific">3.2
|
656 |
Specific</a> <o:p></o:p></span></li>
|
657 |
</ul>
|
658 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
659 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
660 |
style='font-size:10.0pt;font-family:Arial'><a
|
661 |
href="cppstyle.html#Files">4 Files</a> <o:p></o:p></span></li>
|
662 |
<ul type=circle>
|
663 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
664 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
665 |
style='font-size:10.0pt;font-family:Arial'><a
|
666 |
href="cppstyle.html#Source_Files">4.1
|
667 |
Source Files</a> <o:p></o:p></span></li>
|
668 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
669 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
670 |
style='font-size:10.0pt;font-family:Arial'><a
|
671 |
href="cppstyle.html#Include_Files">4.2
|
672 |
Include Files and Include Statements</a> <o:p></o:p></span></li>
|
673 |
</ul>
|
674 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
675 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
676 |
style='font-size:10.0pt;font-family:Arial'><a
|
677 |
href="cppstyle.html#Statements">5
|
678 |
Statements</a> <o:p></o:p></span></li>
|
679 |
<ul type=circle>
|
680 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
681 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
682 |
style='font-size:10.0pt;font-family:Arial'><a
|
683 |
href="cppstyle.html#Types">5.1 Types</a> <o:p></o:p></span></li>
|
684 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
685 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
686 |
style='font-size:10.0pt;font-family:Arial'><a
|
687 |
href="cppstyle.html#Variables">5.2
|
688 |
Variables</a> <o:p></o:p></span></li>
|
689 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
690 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
691 |
style='font-size:10.0pt;font-family:Arial'><a
|
692 |
href="cppstyle.html#Loops">5.3 Loops</a> <o:p></o:p></span></li>
|
693 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
694 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
695 |
style='font-size:10.0pt;font-family:Arial'><a
|
696 |
href="cppstyle.html#Conditionals">5.4
|
697 |
Conditionals</a> <o:p></o:p></span></li>
|
698 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
699 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
700 |
style='font-size:10.0pt;font-family:Arial'><a
|
701 |
href="cppstyle.html#Template">5.5
|
702 |
Template</a> <o:p></o:p></span></li>
|
703 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
704 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
705 |
style='font-size:10.0pt;font-family:Arial'><a
|
706 |
href="cppstyle.html#Misc">5.6
|
707 |
Miscellaneous</a> <o:p></o:p></span></li>
|
708 |
</ul>
|
709 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
710 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
711 |
style='font-size:10.0pt;font-family:Arial'><a
|
712 |
href="cppstyle.html#Layout_and_Comments">6
|
713 |
Layout and White Space</a><span style='mso-spacerun:yes'> </span><o:p></o:p></span></li>
|
714 |
<ul type=circle>
|
715 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
716 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
717 |
style='font-size:10.0pt;font-family:Arial'><a
|
718 |
href="cppstyle.html#Layout">6.1 Layout</a>
|
719 |
<o:p></o:p></span></li>
|
720 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
721 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
722 |
style='font-size:10.0pt;font-family:Arial'><a
|
723 |
href="cppstyle.html#White_Space">6.2
|
724 |
White space</a> <span class=MsoHyperlink><span style='color:windowtext;
|
725 |
text-decoration:none;text-underline:none'><o:p></o:p></span></span></span></li>
|
726 |
</ul>
|
727 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
728 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span
|
729 |
class=MsoHyperlink><span lang=EN-US style='font-size:10.0pt'><a
|
730 |
href="cppstyle.html#Comments_and_Documentation">7 Comments and Documentation</a> <span style='mso-spacerun:yes'></span></span></span></li>
|
731 |
<ul type=circle>
|
732 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
733 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
734 |
style='font-size:10.0pt;font-family:Arial'><a
|
735 |
href="cppstyle.html#Comment">7.1 Comment</a>
|
736 |
<o:p></o:p></span></li>
|
737 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
738 |
auto;mso-list:l0 level2 lfo3;tab-stops:list 72.0pt'><span lang=EN-US
|
739 |
style='font-size:10.0pt;font-family:Arial'><a
|
740 |
href="cppstyle.html#Documentation">7.2
|
741 |
Documentation</a> <span class=MsoHyperlink><span style='color:windowtext;
|
742 |
text-decoration:none;text-underline:none'><o:p></o:p></span></span></span></li>
|
743 |
</ul>
|
744 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
745 |
auto;mso-list:l0 level1 lfo3;tab-stops:list 36.0pt'><span lang=EN-US
|
746 |
style='font-size:10.0pt;font-family:Arial'><a
|
747 |
href="cppstyle.html#References">8
|
748 |
References</a> <o:p></o:p></span></li>
|
749 |
</ul>
|
750 |
<div class=MsoNormal align=center style='text-align:center'><span lang=EN-US
|
751 |
style='font-size:10.0pt;font-family:Arial'>
|
752 |
<hr size=3 width="100%" align=center>
|
753 |
</span></div>
|
754 |
<h2><a name=introduction></a><span lang=EN-US>1 Introduction</span></h2>
|
755 |
<p><span lang=EN-US>This document lists C++ coding recommendations common in
|
756 |
the C++ development community. </span></p>
|
757 |
<p><span lang=EN-US>The recommendations are based on established standards
|
758 |
collected from a number of sources, individual experience, local
|
759 |
requirements/needs, as well as suggestions given in <a
|
760 |
href="cppstyle.html#ref1">[1]</a> - <a
|
761 |
href="cppstyle.html#ref4">[4]</a>. </span></p>
|
762 |
<p><span lang=EN-US>There are several reasons for introducing a new guideline
|
763 |
rather than just referring to the ones above. Main reason is that these
|
764 |
guides are far too general in their scope and that more specific rules
|
765 |
(especially naming rules) need to be established. Also, the present guide has
|
766 |
an annotated form that makes it far easier to use during project code reviews
|
767 |
than most other existing guidelines. In addition, programming recommendations
|
768 |
generally tend to mix style issues with language technical issues in a
|
769 |
somewhat confusing manner. The present document does not contain any C++
|
770 |
technical recommendations at all, but focuses mainly on programming style.
|
771 |
For guidelines on C++ programming <em><span style='font-family:Arial'>style</span></em>
|
772 |
refer to the <a href="http://geosoft.no/cpp.html">C++ Programming Practice
|
773 |
Guidelines</a>. </span></p>
|
774 |
<p><span lang=EN-US>While a given development environment (IDE) can improve
|
775 |
the readability of code by access visibility, color coding, automatic
|
776 |
formatting and so on, the programmer should never <em><span style='font-family:
|
777 |
Arial'>rely</span></em> on such features. Source code should always be
|
778 |
considered <em><span style='font-family:Arial'>larger</span></em> than the
|
779 |
IDE it is developed within and should be written in <span class=GramE>a way
|
780 |
that maximize</span> its readability independent of any IDE. </span></p>
|
781 |
<h3><a name="Layout_of_the_Recommendations"></a><span lang=EN-US>1.1 Layout
|
782 |
of the Recommendations.</span></h3>
|
783 |
<p><span lang=EN-US>The recommendations are grouped by topic and each
|
784 |
recommendation is numbered to make it easier to refer to during reviews. </span></p>
|
785 |
<p><span lang=EN-US>Layout of the recommendations is as follows: </span></p>
|
786 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
787 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
788 |
<tr style='mso-yfti-irow:0'>
|
789 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
790 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
791 |
Arial'>Guideline short description <o:p></o:p></span></b></p>
|
792 |
</td>
|
793 |
</tr>
|
794 |
<tr style='mso-yfti-irow:1'>
|
795 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
796 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>Good example if
|
797 |
applicable</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
798 |
Arial'><o:p></o:p></span></p>
|
799 |
</td>
|
800 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>Bad example if applicable</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
801 |
Arial'><o:p></o:p></span></span></td>
|
802 |
</tr>
|
803 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
804 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
805 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
806 |
Arial'>Motivation, background and additional information. <o:p></o:p></span></p>
|
807 |
</td>
|
808 |
</tr>
|
809 |
</table>
|
810 |
<p><span lang=EN-US>The motivation section is important. Coding standards and
|
811 |
guidelines tend to start "religious wars", and it is important to
|
812 |
state the background for the recommendation. </span></p>
|
813 |
<h3><a name=Recommendation></a><span lang=EN-US>1.2 Recommendation Importance</span></h3>
|
814 |
<p><span lang=EN-US>In the guideline sections the terms <i>must</i>, <i>should
|
815 |
</i>and <i>can </i>have special meaning. A <i>must </i>requirement must be
|
816 |
followed, <span class=GramE>a <i>should</i></span><i> </i>is a strong
|
817 |
recommendation, and a <i>can </i>is a general guideline. </span></p>
|
818 |
<h2><a name="General_Recomendations"></a><span lang=EN-US>2 General
|
819 |
Recommendations<o:p></o:p></span></h2>
|
820 |
<!--
|
821 |
****************************************************************************
|
822 |
Rule
|
823 |
****************************************************************************
|
824 |
-->
|
825 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
826 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
827 |
<tr style='mso-yfti-irow:0'>
|
828 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
829 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
830 |
Arial'>1. Any violation to the guide is allowed if it enhances readability.
|
831 |
<o:p></o:p></span></b></p>
|
832 |
</td>
|
833 |
</tr>
|
834 |
<tr style='mso-yfti-irow:1'>
|
835 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
836 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
837 |
Arial'><o:p> </o:p></span></p>
|
838 |
</td>
|
839 |
</tr>
|
840 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
841 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
842 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
843 |
Arial'>The main goal of the recommendation is to improve readability and
|
844 |
thereby the understanding and the maintainability and general quality of
|
845 |
the code. It is impossible to cover all the specific cases in a general
|
846 |
guide and the programmer should be flexible. <o:p></o:p></span></p>
|
847 |
</td>
|
848 |
</tr>
|
849 |
</table>
|
850 |
<!--
|
851 |
****************************************************************************
|
852 |
Rule
|
853 |
****************************************************************************
|
854 |
-->
|
855 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
856 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
857 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
858 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
859 |
<tr style='mso-yfti-irow:0'>
|
860 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
861 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
862 |
Arial'>2. The rules can be violated if there are strong personal objections
|
863 |
against them. <o:p></o:p></span></b></p>
|
864 |
</td>
|
865 |
</tr>
|
866 |
<tr style='mso-yfti-irow:1'>
|
867 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
868 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
869 |
Arial'><o:p> </o:p></span></p>
|
870 |
</td>
|
871 |
</tr>
|
872 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
873 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
874 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
875 |
Arial'>The attempt is to make a guideline, not to force a particular coding
|
876 |
style onto individuals. Experienced programmers normally want adopt a style
|
877 |
like this anyway, but having one, and at least requiring everyone to get
|
878 |
familiar with it, usually makes people start <em><span style='font-family:
|
879 |
Arial'>thinking</span></em> about programming style and evaluate their own
|
880 |
habits in this area. <o:p></o:p></span></p>
|
881 |
<p><span lang=EN-US>On the other hand, new and inexperienced programmers
|
882 |
normally use a style guide as a convenience of getting into the programming
|
883 |
jargon more easily. </span></p>
|
884 |
</td>
|
885 |
</tr>
|
886 |
</table>
|
887 |
<p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
888 |
line-break'>
|
889 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
890 |
<![endif]></span></p>
|
891 |
<h2><a name="Naming_Conventions"></a><span lang=EN-US>3 Naming Conventions</span></h2>
|
892 |
<h3><a name=General></a><span lang=EN-US>3.1 General Naming Conventions<o:p></o:p></span></h3>
|
893 |
<!--
|
894 |
****************************************************************************
|
895 |
Rule
|
896 |
****************************************************************************
|
897 |
-->
|
898 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
899 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
900 |
<tr style='mso-yfti-irow:0'>
|
901 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
902 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
903 |
Arial'>3. Names representing types must be in mixed case starting with
|
904 |
upper case. <o:p></o:p></span></b></p>
|
905 |
</td>
|
906 |
</tr>
|
907 |
<tr style='mso-yfti-irow:1'>
|
908 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
909 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>Line,
|
910 |
SavingsAccount </span></tt><span lang=EN-US style='font-size:10.0pt;
|
911 |
font-family:Arial'><o:p></o:p></span></p>
|
912 |
</td>
|
913 |
</tr>
|
914 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
915 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
916 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
917 |
Arial'>Common practice in the C++ development community. <o:p></o:p></span></p>
|
918 |
</td>
|
919 |
</tr>
|
920 |
</table>
|
921 |
<!--
|
922 |
****************************************************************************
|
923 |
Rule
|
924 |
****************************************************************************
|
925 |
-->
|
926 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
927 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
928 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
929 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
930 |
<tr style='mso-yfti-irow:0'>
|
931 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
932 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
933 |
Arial'>4. Variable names must be in mixed case starting with lower case. <o:p></o:p></span></b></p>
|
934 |
</td>
|
935 |
</tr>
|
936 |
<tr style='mso-yfti-irow:1'>
|
937 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
938 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>line,
|
939 |
savingsAccount </span></tt><span lang=EN-US style='font-size:10.0pt;
|
940 |
font-family:Arial'><o:p></o:p></span></p>
|
941 |
</td>
|
942 |
</tr>
|
943 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
944 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
945 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
946 |
Arial'>Common practice in the C++ development community. Makes variables
|
947 |
easy to distinguish from types, and effectively resolves potential naming
|
948 |
collision as in the declaration Line line; <o:p></o:p></span></p>
|
949 |
</td>
|
950 |
</tr>
|
951 |
</table>
|
952 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
953 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
954 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
955 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
956 |
<tr style='mso-yfti-irow:0'>
|
957 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
958 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
959 |
Arial'><!--
|
960 |
****************************************************************************
|
961 |
Rule
|
962 |
****************************************************************************
|
963 |
-->5. Named constants (including enumeration values) must be all uppercase
|
964 |
using underscore to separate words. <o:p></o:p></span></b></p>
|
965 |
</td>
|
966 |
</tr>
|
967 |
<tr style='mso-yfti-irow:1'>
|
968 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
969 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>MAX_ITERATIONS,
|
970 |
COLOR_RED, PI </span></tt><span lang=EN-US style='font-size:10.0pt;
|
971 |
font-family:Arial'><o:p></o:p></span></p>
|
972 |
</td>
|
973 |
</tr>
|
974 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
975 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
976 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
977 |
Arial'>Common practice in the C++ development community. In general, the
|
978 |
use of such constants should be minimized. In many cases implementing the
|
979 |
value as a method is a better choice: <o:p></o:p></span></p>
|
980 |
<p><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
981 |
10.0pt'>int getMaxIterations() // NOT: MAX_ITERATIONS = 25 </span></tt><span
|
982 |
lang=EN-US style='font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
983 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
984 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
985 |
return 25;</span></tt><br>
|
986 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span></p>
|
987 |
<p><span lang=EN-US>This form is both easier to read, and it ensures a
|
988 |
unified interface towards class values. </span></p>
|
989 |
</td>
|
990 |
</tr>
|
991 |
</table>
|
992 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
993 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
994 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
995 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
996 |
<tr style='mso-yfti-irow:0'>
|
997 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
998 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
999 |
Arial'><!--
|
1000 |
****************************************************************************
|
1001 |
Rule
|
1002 |
****************************************************************************
|
1003 |
-->6. Names representing methods or functions must be verbs and written in
|
1004 |
mixed case starting with lower case. <o:p></o:p></span></b></p>
|
1005 |
</td>
|
1006 |
</tr>
|
1007 |
<tr style='mso-yfti-irow:1'>
|
1008 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1009 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>getName(),
|
1010 |
computeTotalWidth() </span></tt><span lang=EN-US style='font-size:10.0pt;
|
1011 |
font-family:Arial'><o:p></o:p></span></p>
|
1012 |
</td>
|
1013 |
</tr>
|
1014 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1015 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1016 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1017 |
Arial'>Common practice in the C++ development community. This is identical
|
1018 |
to variable names, but functions in C++ are already distingushable from
|
1019 |
variables by their specific form. <o:p></o:p></span></p>
|
1020 |
</td>
|
1021 |
</tr>
|
1022 |
</table>
|
1023 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1024 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1025 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1026 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1027 |
<tr style='mso-yfti-irow:0'>
|
1028 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1029 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1030 |
Arial'><!--
|
1031 |
****************************************************************************
|
1032 |
Rule
|
1033 |
****************************************************************************
|
1034 |
-->7. Names representing namespaces should be all lowercase. <o:p></o:p></span></b></p>
|
1035 |
</td>
|
1036 |
</tr>
|
1037 |
<tr style='mso-yfti-irow:1'>
|
1038 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1039 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>analyzer,
|
1040 |
iomanager, mainwindow </span></tt><span lang=EN-US style='font-size:10.0pt;
|
1041 |
font-family:Arial'><o:p></o:p></span></p>
|
1042 |
</td>
|
1043 |
</tr>
|
1044 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1045 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1046 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1047 |
Arial'>Common practice in the C++ development community. <o:p></o:p></span></p>
|
1048 |
</td>
|
1049 |
</tr>
|
1050 |
</table>
|
1051 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1052 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1053 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1054 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1055 |
<tr style='mso-yfti-irow:0'>
|
1056 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1057 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1058 |
Arial'><!--
|
1059 |
****************************************************************************
|
1060 |
Rule
|
1061 |
****************************************************************************
|
1062 |
-->8. Names representing template types should be a single uppercase letter. <o:p></o:p></span></b></p>
|
1063 |
</td>
|
1064 |
</tr>
|
1065 |
<tr style='mso-yfti-irow:1'>
|
1066 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1067 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>template<typename
|
1068 |
T> ... </span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1069 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
1070 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>template<typename
|
1071 |
C, typename D> ... </span></tt></span><span lang=EN-US style='font-size:
|
1072 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1073 |
</td>
|
1074 |
</tr>
|
1075 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1076 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1077 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1078 |
Arial'>Common practice in the C++ development community. This makes
|
1079 |
template names stand out relative to all other names used. <o:p></o:p></span></p>
|
1080 |
</td>
|
1081 |
</tr>
|
1082 |
</table>
|
1083 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1084 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1085 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1086 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1087 |
<tr style='mso-yfti-irow:0'>
|
1088 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1089 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1090 |
Arial'><!--
|
1091 |
****************************************************************************
|
1092 |
Rule
|
1093 |
****************************************************************************
|
1094 |
-->9. Abbreviations and acronyms must not be uppercase when used as name [4]. <o:p></o:p></span></b></p>
|
1095 |
</td>
|
1096 |
</tr>
|
1097 |
<tr style='mso-yfti-irow:1'>
|
1098 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1099 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>exportHtmlSource();</span></tt><span lang=EN-US
|
1100 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1101 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>openDvdPlayer();</span></tt></span><span
|
1102 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1103 |
</td>
|
1104 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'> exportHTMLSource();</span></tt><span lang=EN-US
|
1105 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1106 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>openDVDPlayer(); </span></tt></span><span
|
1107 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
1108 |
</tr>
|
1109 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1110 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
1111 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1112 |
Arial'>Using all uppercase for the base name will give conflicts with the
|
1113 |
naming conventions given above. A variable of this type whould have to be
|
1114 |
named dVD, hTML etc. which obviously is not very readable. Another problem
|
1115 |
is illustrated in the examples above; When the name is connected to
|
1116 |
another, the readbility is seriously reduced; the word following the
|
1117 |
abbreviation does not stand out as it should. <o:p></o:p></span></p>
|
1118 |
</td>
|
1119 |
</tr>
|
1120 |
</table>
|
1121 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1122 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1123 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1124 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1125 |
<tr style='mso-yfti-irow:0'>
|
1126 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1127 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1128 |
Arial'><!--
|
1129 |
****************************************************************************
|
1130 |
Rule
|
1131 |
****************************************************************************
|
1132 |
-->10. Global variables should always be referred to using <span class=GramE>the
|
1133 |
:</span>: operator. <o:p></o:p></span></b></p>
|
1134 |
</td>
|
1135 |
</tr>
|
1136 |
<tr style='mso-yfti-irow:1'>
|
1137 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1138 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>::mainWindow.open(),
|
1139 |
::applicationContext.getName() </span></tt><span lang=EN-US
|
1140 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1141 |
</td>
|
1142 |
</tr>
|
1143 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1144 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1145 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1146 |
Arial'>In general, the use of global variables should be avoided. Consider
|
1147 |
using singleton objects instead. <o:p></o:p></span></p>
|
1148 |
</td>
|
1149 |
</tr>
|
1150 |
</table>
|
1151 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1152 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1153 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1154 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1155 |
<tr style='mso-yfti-irow:0'>
|
1156 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1157 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1158 |
Arial'><!--
|
1159 |
***************************************************************************
|
1160 |
Rule
|
1161 |
****************************************************************************
|
1162 |
-->11. Private class variables should have underscore suffix. <o:p></o:p></span></b></p>
|
1163 |
</td>
|
1164 |
</tr>
|
1165 |
<tr style='mso-yfti-irow:1'>
|
1166 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1167 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>class
|
1168 |
SomeClass {</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1169 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
1170 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1171 |
private:</span></tt><br>
|
1172 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1173 |
int length_;</span></tt><br>
|
1174 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span
|
1175 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1176 |
</td>
|
1177 |
</tr>
|
1178 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1179 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1180 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1181 |
Arial'>Apart from its name and its type, the <em><span style='font-family:
|
1182 |
Arial'>scope</span></em> of a variable is its most important feature.
|
1183 |
Indicating class scope by using underscore makes it easy to distinguish
|
1184 |
class variables from local scratch variables. This is important because
|
1185 |
class variables are considered to have higher significance than method
|
1186 |
variables, and should be treated with special care by the programmer. <o:p></o:p></span></p>
|
1187 |
<p><span lang=EN-US>A side effect of the underscore naming convention is
|
1188 |
that it nicely resolves the problem of finding reasonable variable names
|
1189 |
for setter methods and constructors: </span></p>
|
1190 |
<p><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1191 |
10.0pt'>void setDepth (int depth)</span></tt><span lang=EN-US
|
1192 |
style='font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1193 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
1194 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1195 |
depth_ = depth;</span></tt><br>
|
1196 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span></p>
|
1197 |
<p><span lang=EN-US>An issue is whether the underscore should be added as a
|
1198 |
prefix or as a suffix. Both practices are commonly used, but the latter is
|
1199 |
recommended because it <span class=GramE>seem</span> to best preserve the
|
1200 |
readability of the name. </span></p>
|
1201 |
<p><span lang=EN-US>It should be noted that scope identification in
|
1202 |
variables has been a controversial issue for quite some time. It seems,
|
1203 |
though, that this practice now is gaining acceptance and that it is
|
1204 |
becoming more and more common as a convention in the professional
|
1205 |
development community. </span></p>
|
1206 |
</td>
|
1207 |
</tr>
|
1208 |
</table>
|
1209 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1210 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1211 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1212 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1213 |
<tr style='mso-yfti-irow:0'>
|
1214 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1215 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1216 |
Arial'><!--
|
1217 |
****************************************************************************
|
1218 |
Rule
|
1219 |
****************************************************************************
|
1220 |
-->12. Generic variables should have the same name as their type. <o:p></o:p></span></b></p>
|
1221 |
</td>
|
1222 |
</tr>
|
1223 |
<tr style='mso-yfti-irow:1'>
|
1224 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
1225 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>void
|
1226 |
setTopic (Topic *topic)</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1227 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
1228 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1229 |
</span></tt><br>
|
1230 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt><br>
|
1231 |
<br>
|
1232 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>void
|
1233 |
connect (Database *database)</span></tt><br>
|
1234 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1235 |
</span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
1236 |
font-family:Arial'><o:p></o:p></span></p>
|
1237 |
</td>
|
1238 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>void setTopic (Topic *value)</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1239 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
1240 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>void setTopic (Topic *aTopic) </span></tt><br>
|
1241 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>void setTopic (Topic *x) </span></tt><br>
|
1242 |
<br>
|
1243 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>void connect (Database *db)</span></tt><br>
|
1244 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> void connect (Database *oracleDB) </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
1245 |
font-family:Arial'><o:p></o:p></span></span></td>
|
1246 |
</tr>
|
1247 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1248 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
1249 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1250 |
Arial'>Reduce complexity by reducing the number of terms and names used.
|
1251 |
Also makes it easy to deduce the type given a variable name only. <o:p></o:p></span></p>
|
1252 |
<p><span lang=EN-US>If for some reason this convention doesn't seem to <em><span
|
1253 |
style='font-family:Arial'>fit</span></em> it is a strong indication that
|
1254 |
the type name is badly chosen. </span></p>
|
1255 |
<p><span lang=EN-US>Non-generic variables have a <em><span
|
1256 |
style='font-family:Arial'>role</span></em>. These variables can often be
|
1257 |
named by combining role and type: </span></p>
|
1258 |
<p><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1259 |
10.0pt'>Point startingPoint, centerPoint;</span></tt><span lang=EN-US
|
1260 |
style='font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1261 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>Name
|
1262 |
loginName;</span></tt></span></p>
|
1263 |
</td>
|
1264 |
</tr>
|
1265 |
</table>
|
1266 |
<p style='margin:0cm;margin-bottom:.0001pt'><!--
|
1267 |
****************************************************************************
|
1268 |
Rule
|
1269 |
****************************************************************************
|
1270 |
--><span lang=EN-US style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1271 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1272 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1273 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1274 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1275 |
<tr style='mso-yfti-irow:0'>
|
1276 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1277 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1278 |
Arial'><!--
|
1279 |
****************************************************************************
|
1280 |
Rule
|
1281 |
****************************************************************************
|
1282 |
-->
|
1283 |
13. Variables with a large scope should have long names, variables with a
|
1284 |
small scope can have short names [1]. <o:p></o:p></span></b></p>
|
1285 |
</td>
|
1286 |
</tr>
|
1287 |
<tr style='mso-yfti-irow:1'>
|
1288 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1289 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
1290 |
Arial'><o:p> </o:p></span></p>
|
1291 |
</td>
|
1292 |
</tr>
|
1293 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1294 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1295 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1296 |
Arial'>Scratch variables used for temporary storage or indices are best
|
1297 |
kept short. A programmer reading such variables should be able to assume
|
1298 |
that its value is not used outside a few lines of code. Common scratch
|
1299 |
variables for integers are <em><span style='font-family:Arial'>i</span></em>,
|
1300 |
<em><span style='font-family:Arial'>j</span></em>, <em><span
|
1301 |
style='font-family:Arial'>k</span></em>, <em><span style='font-family:Arial'>m</span></em>,
|
1302 |
<em><span style='font-family:Arial'>n</span></em> and for characters <em><span
|
1303 |
style='font-family:Arial'>c</span></em> and <em><span style='font-family:
|
1304 |
Arial'>d</span></em>. <o:p></o:p></span></p>
|
1305 |
</td>
|
1306 |
</tr>
|
1307 |
</table>
|
1308 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1309 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1310 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1311 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1312 |
<tr style='mso-yfti-irow:0'>
|
1313 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1314 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1315 |
Arial'><!--
|
1316 |
****************************************************************************
|
1317 |
Rule
|
1318 |
****************************************************************************
|
1319 |
-->
|
1320 |
14. The name of the object is implicit, and should be avoided in a method
|
1321 |
name. <o:p></o:p></span></b></p>
|
1322 |
</td>
|
1323 |
</tr>
|
1324 |
<tr style='mso-yfti-irow:1'>
|
1325 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1326 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>line.getLength();
|
1327 |
// NOT: line.getLineLength(); </span></tt><span lang=EN-US
|
1328 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1329 |
</td>
|
1330 |
</tr>
|
1331 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1332 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1333 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1334 |
Arial'>The latter seems natural in the class declaration, but proves
|
1335 |
superfluous in use, as shown in the example. <o:p></o:p></span></p>
|
1336 |
</td>
|
1337 |
</tr>
|
1338 |
</table>
|
1339 |
<h3><a name=Specific></a><span lang=EN-US>3.2 Specific Naming Conventions<o:p></o:p></span></h3>
|
1340 |
<!--
|
1341 |
****************************************************************************
|
1342 |
Rule
|
1343 |
****************************************************************************
|
1344 |
-->
|
1345 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1346 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1347 |
<tr style='mso-yfti-irow:0'>
|
1348 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1349 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1350 |
Arial'>15. The terms <i>get/set</i> must be used where an attribute is
|
1351 |
accessed directly. <o:p></o:p></span></b></p>
|
1352 |
</td>
|
1353 |
</tr>
|
1354 |
<tr style='mso-yfti-irow:1'>
|
1355 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1356 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>employee.getName();
|
1357 |
matrix.getElement (2, 4);</span></tt><span lang=EN-US style='font-size:
|
1358 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1359 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>employee.setName
|
1360 |
(name); matrix.setElement (2, 4, value); </span></tt></span><span
|
1361 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1362 |
</td>
|
1363 |
</tr>
|
1364 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1365 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1366 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1367 |
Arial'>Common practice in the C++ development community. In Java this
|
1368 |
convention has become more or less standard. <o:p></o:p></span></p>
|
1369 |
</td>
|
1370 |
</tr>
|
1371 |
</table>
|
1372 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1373 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1374 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1375 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1376 |
<tr style='mso-yfti-irow:0'>
|
1377 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1378 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1379 |
Arial'><!--
|
1380 |
****************************************************************************
|
1381 |
Rule
|
1382 |
****************************************************************************
|
1383 |
-->16. The term <i>compute</i> can be used in methods where something is
|
1384 |
computed. <o:p></o:p></span></b></p>
|
1385 |
</td>
|
1386 |
</tr>
|
1387 |
<tr style='mso-yfti-irow:1'>
|
1388 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1389 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>valueSet->computeAverage();
|
1390 |
matrix->computeInverse() </span></tt><span lang=EN-US style='font-size:
|
1391 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1392 |
</td>
|
1393 |
</tr>
|
1394 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1395 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1396 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1397 |
Arial'>Give the reader the immediate clue that this is a potential time
|
1398 |
consuming operation, and if used repeatedly, he might consider caching the
|
1399 |
result. Consistent use of the term enhances readability. <o:p></o:p></span></p>
|
1400 |
</td>
|
1401 |
</tr>
|
1402 |
</table>
|
1403 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1404 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1405 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1406 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1407 |
<tr style='mso-yfti-irow:0'>
|
1408 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1409 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1410 |
Arial'><!--
|
1411 |
****************************************************************************
|
1412 |
Rule
|
1413 |
****************************************************************************
|
1414 |
-->17. The term <i>find</i> can be used in methods where something is looked
|
1415 |
up. <o:p></o:p></span></b></p>
|
1416 |
</td>
|
1417 |
</tr>
|
1418 |
<tr style='mso-yfti-irow:1'>
|
1419 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1420 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>vertex.findNearestVertex();
|
1421 |
matrix.findMinElement(); </span></tt><span lang=EN-US
|
1422 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1423 |
</td>
|
1424 |
</tr>
|
1425 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1426 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1427 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1428 |
Arial'>Give the reader the immediate clue that this is a simple look up
|
1429 |
method with a minimum of computations involved. Consistent use of the term
|
1430 |
enhances readability. <o:p></o:p></span></p>
|
1431 |
</td>
|
1432 |
</tr>
|
1433 |
</table>
|
1434 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1435 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1436 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1437 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1438 |
<tr style='mso-yfti-irow:0'>
|
1439 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1440 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1441 |
Arial'><!--
|
1442 |
****************************************************************************
|
1443 |
Rule
|
1444 |
****************************************************************************
|
1445 |
-->18. The term <i>initialize</i> can be used where an object or a concept is
|
1446 |
established. <o:p></o:p></span></b></p>
|
1447 |
</td>
|
1448 |
</tr>
|
1449 |
<tr style='mso-yfti-irow:1'>
|
1450 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1451 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>printer.initializeFontSet();
|
1452 |
</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1453 |
</td>
|
1454 |
</tr>
|
1455 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1456 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1457 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1458 |
Arial'>The american <i>initialize </i>should be preferred over the english <i>initialise</i>.
|
1459 |
Abbreviation <i>init </i>should be avoided.<o:p></o:p></span></p>
|
1460 |
</td>
|
1461 |
</tr>
|
1462 |
</table>
|
1463 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1464 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1465 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1466 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1467 |
<tr style='mso-yfti-irow:0'>
|
1468 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1469 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1470 |
Arial'><!--
|
1471 |
****************************************************************************
|
1472 |
Rule
|
1473 |
****************************************************************************
|
1474 |
-->19. Variables representing GUI components should be suffixed by the
|
1475 |
component type name. <o:p></o:p></span></b></p>
|
1476 |
</td>
|
1477 |
</tr>
|
1478 |
<tr style='mso-yfti-irow:1'>
|
1479 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1480 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>mainWindow,
|
1481 |
propertiesDialog, widthScale, loginText, leftScrollbar, mainForm, fileMenu,
|
1482 |
minLabel, exitButton, yesToggle etc. </span></tt><span lang=EN-US
|
1483 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1484 |
</td>
|
1485 |
</tr>
|
1486 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1487 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1488 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1489 |
Arial'>Enhances readability since the name gives the user an immediate clue
|
1490 |
of the type of the variable and thereby the objects resources. <o:p></o:p></span></p>
|
1491 |
</td>
|
1492 |
</tr>
|
1493 |
</table>
|
1494 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1495 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1496 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1497 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1498 |
<tr style='mso-yfti-irow:0'>
|
1499 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1500 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1501 |
Arial'><!--
|
1502 |
****************************************************************************
|
1503 |
Rule
|
1504 |
****************************************************************************
|
1505 |
-->20. The suffix <i>List</i> can be used on names representing a list of
|
1506 |
objects. <o:p></o:p></span></b></p>
|
1507 |
</td>
|
1508 |
</tr>
|
1509 |
<tr style='mso-yfti-irow:1'>
|
1510 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1511 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>vertex </span></tt><span
|
1512 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'>(one
|
1513 |
vertex), </span><tt><span lang=EN-US style='font-size:10.0pt'>vertexList
|
1514 |
</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>(a
|
1515 |
list of vertices) <o:p></o:p></span></p>
|
1516 |
</td>
|
1517 |
</tr>
|
1518 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1519 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1520 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1521 |
Arial'>Enhances readability since the name gives the user an immediate clue
|
1522 |
of the type of the variable and the operations that can be performed on the
|
1523 |
object. <o:p></o:p></span></p>
|
1524 |
<p><span lang=EN-US>Simply using the plural form of the base class name for
|
1525 |
a list (</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1526 |
mso-bidi-font-size:10.0pt'>matrixElement </span></tt><span lang=EN-US>(one
|
1527 |
matrix element), </span><tt><span lang=EN-US style='mso-ansi-font-size:
|
1528 |
10.0pt;mso-bidi-font-size:10.0pt'>matrixElements </span></tt><span
|
1529 |
lang=EN-US>(list of matrix elements)) shoul be avoided since the two only
|
1530 |
differ in a single character and are thereby difficult to distinguish. </span></p>
|
1531 |
<p><span lang=EN-US>A <i>list</i> in this context is the compound data type
|
1532 |
that can be traversed backwards, forwards, etc. (typically an STL </span><tt><span
|
1533 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>vector</span></tt><span
|
1534 |
lang=EN-US>). A plain array is simpler. The suffix <i>Array</i> can be used
|
1535 |
to denote an array of objects. </span></p>
|
1536 |
</td>
|
1537 |
</tr>
|
1538 |
</table>
|
1539 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1540 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1541 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1542 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1543 |
<tr style='mso-yfti-irow:0'>
|
1544 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1545 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1546 |
Arial'><!--
|
1547 |
****************************************************************************
|
1548 |
Rule
|
1549 |
****************************************************************************
|
1550 |
-->21. The prefix <i>n</i> should be used for variables representing a number
|
1551 |
of objects. <o:p></o:p></span></b></p>
|
1552 |
</td>
|
1553 |
</tr>
|
1554 |
<tr style='mso-yfti-irow:1'>
|
1555 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1556 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>nPoints,
|
1557 |
nLines </span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1558 |
Arial'><o:p></o:p></span></p>
|
1559 |
</td>
|
1560 |
</tr>
|
1561 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1562 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1563 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1564 |
Arial'>The notation is taken from mathematics where it is an established
|
1565 |
convention for indicating a number of objects. <o:p></o:p></span></p>
|
1566 |
</td>
|
1567 |
</tr>
|
1568 |
</table>
|
1569 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1570 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1571 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1572 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1573 |
<tr style='mso-yfti-irow:0'>
|
1574 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1575 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1576 |
Arial'><!--
|
1577 |
****************************************************************************
|
1578 |
Rule
|
1579 |
****************************************************************************
|
1580 |
--><span class=GramE>22.The</span> suffix <i>No</i> should be used for
|
1581 |
variables representing an entity number. <o:p></o:p></span></b></p>
|
1582 |
</td>
|
1583 |
</tr>
|
1584 |
<tr style='mso-yfti-irow:1'>
|
1585 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1586 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>tableNo,
|
1587 |
employeeNo </span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
1588 |
Arial'><o:p></o:p></span></p>
|
1589 |
</td>
|
1590 |
</tr>
|
1591 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1592 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1593 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1594 |
Arial'>The notation is taken from mathematics where it is an established
|
1595 |
convention for indicating an entity number. <o:p></o:p></span></p>
|
1596 |
<p><span lang=EN-US>An elegant alternative is to prefix such variables with
|
1597 |
<span class=GramE>an <em><span style='font-family:Arial'>i</span></em></span>:
|
1598 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1599 |
10.0pt'>iTable, iEmployee</span></tt><span lang=EN-US>. This effectively
|
1600 |
makes them <em><span style='font-family:Arial'>named</span></em> iterators.
|
1601 |
</span></p>
|
1602 |
</td>
|
1603 |
</tr>
|
1604 |
</table>
|
1605 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1606 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1607 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1608 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1609 |
<tr style='mso-yfti-irow:0'>
|
1610 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1611 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1612 |
Arial'><!--
|
1613 |
****************************************************************************
|
1614 |
Rule
|
1615 |
****************************************************************************
|
1616 |
-->23. Iterator variables should be called <em><span style='font-family:Arial'>i</span></em>,
|
1617 |
<em><span style='font-family:Arial'>j</span></em>, <em><span
|
1618 |
style='font-family:Arial'>k</span></em> etc. <o:p></o:p></span></b></p>
|
1619 |
</td>
|
1620 |
</tr>
|
1621 |
<tr style='mso-yfti-irow:1'>
|
1622 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1623 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>for (int i
|
1624 |
= 0; i < nTables); i++) {</span></tt><span lang=EN-US style='font-size:
|
1625 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
1626 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1627 |
:</span></tt><br>
|
1628 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt><br>
|
1629 |
<br>
|
1630 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>vector<MyClass>::iterator
|
1631 |
i;</span></tt><br>
|
1632 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for
|
1633 |
(i = list.begin(); i != list.end(); i++) { </span></tt><br>
|
1634 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1635 |
Element element = *i;</span></tt><br>
|
1636 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1637 |
... </span></tt><br>
|
1638 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span
|
1639 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1640 |
</td>
|
1641 |
</tr>
|
1642 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1643 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1644 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1645 |
Arial'>The notation is taken from mathematics where it is an established
|
1646 |
convention for indicating iterators. <o:p></o:p></span></p>
|
1647 |
</td>
|
1648 |
</tr>
|
1649 |
</table>
|
1650 |
<p style='margin:0cm;margin-bottom:.0001pt'><!--
|
1651 |
****************************************************************************
|
1652 |
Rule
|
1653 |
****************************************************************************
|
1654 |
--><span lang=EN-US style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1655 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1656 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1657 |
<tr style='mso-yfti-irow:0'>
|
1658 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1659 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1660 |
Arial'>24. The prefix <i>is</i> should be used for boolean variables and
|
1661 |
methods. <o:p></o:p></span></b></p>
|
1662 |
</td>
|
1663 |
</tr>
|
1664 |
<tr style='mso-yfti-irow:1'>
|
1665 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1666 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>isSet,
|
1667 |
isVisible, isFinished, isFound, isOpen </span></tt><span lang=EN-US
|
1668 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1669 |
</td>
|
1670 |
</tr>
|
1671 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1672 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1673 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1674 |
Arial'>Common practice in the C++ development community and partially
|
1675 |
enforced in Java. <o:p></o:p></span></p>
|
1676 |
<p><span lang=EN-US>Using <span class=GramE>the <i>is</i></span> prefix
|
1677 |
solves a common problem of choosing bad boolean names like </span><tt><span
|
1678 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>status</span></tt><span
|
1679 |
lang=EN-US> or </span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1680 |
mso-bidi-font-size:10.0pt'>flag</span></tt><span lang=EN-US>. </span><span
|
1681 |
class=GramE><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1682 |
mso-bidi-font-size:10.0pt'>isStatus</span></tt></span><tt><span lang=EN-US
|
1683 |
style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt><span
|
1684 |
lang=EN-US>or</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1685 |
mso-bidi-font-size:10.0pt'> isFlag</span></tt><span lang=EN-US> simply
|
1686 |
doesn't fit, and the programmer is forced to choose more meaningful names. </span></p>
|
1687 |
<p><span lang=EN-US>There are a few alternatives to <span class=GramE>the <em><span
|
1688 |
style='font-family:Arial'>is</span></em></span> prefix that fits better in
|
1689 |
some situations. These are the <em><span style='font-family:Arial'>has</span></em>,
|
1690 |
<em><span style='font-family:Arial'>can</span></em> and <em><span
|
1691 |
style='font-family:Arial'>should</span></em> prefixes: </span></p>
|
1692 |
<p><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1693 |
10.0pt'>bool hasLicense(); </span></tt><span lang=EN-US><br>
|
1694 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1695 |
10.0pt'>bool canEvaluate(); </span></tt><span lang=EN-US><br>
|
1696 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1697 |
10.0pt'>bool shouldSort(); </span></tt></p>
|
1698 |
</td>
|
1699 |
</tr>
|
1700 |
</table>
|
1701 |
<p style='margin:0cm;margin-bottom:.0001pt'><!--
|
1702 |
****************************************************************************
|
1703 |
Rule
|
1704 |
****************************************************************************
|
1705 |
--><span lang=EN-US style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1706 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1707 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1708 |
<tr style='mso-yfti-irow:0'>
|
1709 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1710 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1711 |
Arial'>25. Complement names must be used for complement operations [1]. <o:p></o:p></span></b></p>
|
1712 |
</td>
|
1713 |
</tr>
|
1714 |
<tr style='mso-yfti-irow:1'>
|
1715 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1716 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>get/set,
|
1717 |
add/remove, create/destroy, start/stop, insert/delete, increment/decrement,
|
1718 |
old/new, begin/end, first/last, up/down, min/max, next/previous, old/new,
|
1719 |
open/close, show/hide, suspend/resume, etc. </span></tt><span lang=EN-US
|
1720 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1721 |
</td>
|
1722 |
</tr>
|
1723 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1724 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1725 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1726 |
Arial'>Reduce complexity by symmetry.<o:p></o:p></span></p>
|
1727 |
</td>
|
1728 |
</tr>
|
1729 |
</table>
|
1730 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1731 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1732 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1733 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1734 |
<tr style='mso-yfti-irow:0'>
|
1735 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1736 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1737 |
Arial'><!--
|
1738 |
****************************************************************************
|
1739 |
Rule
|
1740 |
****************************************************************************
|
1741 |
-->26. Abbreviations in names should be avoided.<o:p></o:p></span></b></p>
|
1742 |
</td>
|
1743 |
</tr>
|
1744 |
<tr style='mso-yfti-irow:1'>
|
1745 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
1746 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>computeAverage();</span></tt><span lang=EN-US style='font-size:
|
1747 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1748 |
</td>
|
1749 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>compAvg(); </span></tt><span lang=EN-US style='font-size:
|
1750 |
10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
1751 |
</tr>
|
1752 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1753 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
1754 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1755 |
Arial'>There are two types of words to consider. First are the common words
|
1756 |
listed in a language <span class=GramE>dictionary.</span> These must never
|
1757 |
be abbreviated. Never write: <o:p></o:p></span></p>
|
1758 |
<p><span class=GramE><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1759 |
mso-bidi-font-size:10.0pt'>cmd</span></tt></span><tt><span lang=EN-US
|
1760 |
style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt><span
|
1761 |
lang=EN-US> instead of </span><tt><span lang=EN-US style='mso-ansi-font-size:
|
1762 |
10.0pt;mso-bidi-font-size:10.0pt'> command</span></tt><span
|
1763 |
lang=EN-US><br>
|
1764 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1765 |
10.0pt'>cp </span></tt><span lang=EN-US> instead of </span><tt><span
|
1766 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1767 |
copy</span></tt><span lang=EN-US><br>
|
1768 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1769 |
10.0pt'>pt </span></tt><span lang=EN-US> instead of </span><tt><span
|
1770 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1771 |
point</span></tt><span lang=EN-US><br>
|
1772 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1773 |
10.0pt'>comp </span></tt><span lang=EN-US> instead of </span><tt><span
|
1774 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1775 |
compute</span></tt><span lang=EN-US><br>
|
1776 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1777 |
10.0pt'>init </span></tt><span lang=EN-US> instead of </span><tt><span
|
1778 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1779 |
initialize</span></tt><span lang=EN-US><br>
|
1780 |
etc.</span></p>
|
1781 |
<p><span lang=EN-US>Then there are domain specific phrases that are more
|
1782 |
naturally known through their abbreviations/acronym. These phrases should
|
1783 |
be kept abbreviated. Never write: </span></p>
|
1784 |
<p><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1785 |
10.0pt'>HypertextMarkupLanguage </span></tt><span lang=EN-US>instead
|
1786 |
of </span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1787 |
10.0pt'> html</span></tt><span lang=EN-US><br>
|
1788 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1789 |
10.0pt'>CentralProcessingUnit </span></tt><span lang=EN-US>instead
|
1790 |
of </span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1791 |
10.0pt'> cpu</span></tt><span lang=EN-US><br>
|
1792 |
</span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
1793 |
10.0pt'>PriceEarningRatio </span></tt><span
|
1794 |
lang=EN-US>instead of </span><tt><span lang=EN-US style='mso-ansi-font-size:
|
1795 |
10.0pt;mso-bidi-font-size:10.0pt'> pe</span></tt><span lang=EN-US><br>
|
1796 |
etc. </span></p>
|
1797 |
</td>
|
1798 |
</tr>
|
1799 |
</table>
|
1800 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1801 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1802 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1803 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1804 |
<tr style='mso-yfti-irow:0'>
|
1805 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1806 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1807 |
Arial'><!--
|
1808 |
****************************************************************************
|
1809 |
Rule
|
1810 |
****************************************************************************
|
1811 |
-->27. Naming pointers specifically should be avoided. <o:p></o:p></span></b></p>
|
1812 |
</td>
|
1813 |
</tr>
|
1814 |
<tr style='mso-yfti-irow:1'>
|
1815 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
1816 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>Line
|
1817 |
*line; </span></tt><span lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1818 |
</td>
|
1819 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'> Line *pLine; </span></tt></p>
|
1820 |
<p class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>Line *linePtr</span></tt><span class="MsoNormal"><span lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></p> </td>
|
1821 |
</tr>
|
1822 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1823 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
1824 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1825 |
Arial'>Many variables in a C/C++ environment are pointers, so a convention
|
1826 |
like this is almost impossible to follow. Also objects in C++ are often
|
1827 |
oblique types where the specific implementation should be ignored by the
|
1828 |
programmer. Only when the actual type of an object is of special
|
1829 |
significance, the name should empahsize the type. <o:p></o:p></span></p>
|
1830 |
</td>
|
1831 |
</tr>
|
1832 |
</table>
|
1833 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1834 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1835 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1836 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1837 |
<tr style='mso-yfti-irow:0'>
|
1838 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1839 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1840 |
Arial'><!--
|
1841 |
****************************************************************************
|
1842 |
Rule
|
1843 |
****************************************************************************
|
1844 |
-->28. Negated boolean variable names must be avoided. <o:p></o:p></span></b></p>
|
1845 |
</td>
|
1846 |
</tr>
|
1847 |
<tr style='mso-yfti-irow:1'>
|
1848 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
1849 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>bool
|
1850 |
isError;</span></tt><span
|
1851 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
1852 |
"Courier New"'><br>
|
1853 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>bool
|
1854 |
isFound; </span></tt></span><span
|
1855 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1856 |
</td>
|
1857 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>bool isNoError </span></tt><span
|
1858 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
1859 |
"Courier New"'></span></p>
|
1860 |
<p class="MsoNormal"><span
|
1861 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
1862 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>bool isNotFound </span></tt></span></p></td>
|
1863 |
</tr>
|
1864 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1865 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
1866 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1867 |
Arial'>The problem arises when such a name is used in conjunction with the
|
1868 |
logical negation operator as <span class=GramE>this results</span> in a
|
1869 |
double negative. It is not immediately apparent <span class=GramE>what <tt><span
|
1870 |
style='mso-ansi-font-size:7.5pt;mso-bidi-font-size:7.5pt'>!</span></tt></span></span><tt><span
|
1871 |
lang=EN-US style='font-size:7.5pt'>isNotFound</span></tt><span lang=EN-US
|
1872 |
style='font-size:7.5pt;font-family:Arial'> means. <o:p></o:p></span></p>
|
1873 |
</td>
|
1874 |
</tr>
|
1875 |
</table>
|
1876 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1877 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1878 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1879 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1880 |
<tr style='mso-yfti-irow:0'>
|
1881 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1882 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1883 |
Arial'><!--
|
1884 |
****************************************************************************
|
1885 |
Rule
|
1886 |
****************************************************************************
|
1887 |
-->29. Enumeration constants can be prefixed by a common type name. <o:p></o:p></span></b></p>
|
1888 |
</td>
|
1889 |
</tr>
|
1890 |
<tr style='mso-yfti-irow:1'>
|
1891 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1892 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>enum Color
|
1893 |
{</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:fixed;
|
1894 |
mso-bidi-font-family:"Courier New"'><br>
|
1895 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1896 |
COLOR_RED,</span></tt><br>
|
1897 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1898 |
COLOR_GREEN,</span></tt><br>
|
1899 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1900 |
COLOR_BLUE</span></tt><br>
|
1901 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}; </span></tt></span><span
|
1902 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1903 |
</td>
|
1904 |
</tr>
|
1905 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1906 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1907 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1908 |
Arial'>This gives additional information of where the declaration can be
|
1909 |
found, which <span class=GramE>constants belongs</span> together, and what
|
1910 |
concept the constants represent. <o:p></o:p></span></p>
|
1911 |
<p><span lang=EN-US>An alternative approach is to always refer to the
|
1912 |
constants through their common type: </span><tt><span lang=EN-US
|
1913 |
style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>Color::RED</span></tt><span
|
1914 |
lang=EN-US>, </span><tt><span lang=EN-US style='mso-ansi-font-size:10.0pt;
|
1915 |
mso-bidi-font-size:10.0pt'>Airline::AIR_FRANCE</span></tt><span lang=EN-US>
|
1916 |
etc. </span></p>
|
1917 |
</td>
|
1918 |
</tr>
|
1919 |
</table>
|
1920 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1921 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1922 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1923 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1924 |
<tr style='mso-yfti-irow:0'>
|
1925 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1926 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1927 |
Arial'><!--
|
1928 |
****************************************************************************
|
1929 |
Rule
|
1930 |
****************************************************************************
|
1931 |
-->30. Exception classes should be suffixed with <em><span style='font-family:
|
1932 |
Arial'>Exception</span></em>. <o:p></o:p></span></b></p>
|
1933 |
</td>
|
1934 |
</tr>
|
1935 |
<tr style='mso-yfti-irow:1'>
|
1936 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1937 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>class
|
1938 |
AccessException</span></tt><span lang=EN-US style='font-size:10.0pt;
|
1939 |
font-family:fixed;mso-bidi-font-family:"Courier New"'> <tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
1940 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
1941 |
:</span></tt><br>
|
1942 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
1943 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
1944 |
</td>
|
1945 |
</tr>
|
1946 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1947 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1948 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1949 |
Arial'>Exception classes are really not part of the main design of the
|
1950 |
program, and naming them like this makes them stand out relative to the
|
1951 |
other classes. <o:p></o:p></span></p>
|
1952 |
</td>
|
1953 |
</tr>
|
1954 |
</table>
|
1955 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
1956 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
1957 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1958 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1959 |
<tr style='mso-yfti-irow:0'>
|
1960 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
1961 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
1962 |
Arial'><!--
|
1963 |
****************************************************************************
|
1964 |
Rule
|
1965 |
****************************************************************************
|
1966 |
-->31. Functions (methods returning something) should be named after what they
|
1967 |
return and procedures (<i>void</i> methods) after what they do. <o:p></o:p></span></b></p>
|
1968 |
</td>
|
1969 |
</tr>
|
1970 |
<tr style='mso-yfti-irow:1'>
|
1971 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1972 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
1973 |
Arial'><o:p> </o:p></span></p>
|
1974 |
</td>
|
1975 |
</tr>
|
1976 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
1977 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
1978 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
1979 |
Arial'>Increase readability. Makes it clear what the unit should do and
|
1980 |
especially all the things it is not supposed to do. This again makes it
|
1981 |
easier to keep the code clean of side effects. <o:p></o:p></span></p>
|
1982 |
</td>
|
1983 |
</tr>
|
1984 |
</table>
|
1985 |
<p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
1986 |
line-break'>
|
1987 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
1988 |
<![endif]></span></p>
|
1989 |
<h2><a name=Files></a><span lang=EN-US>4 Files</span></h2>
|
1990 |
<h3><a name="Source_Files"></a><span lang=EN-US>4.1 Source Files<o:p></o:p></span></h3>
|
1991 |
<!--
|
1992 |
****************************************************************************
|
1993 |
Rule
|
1994 |
****************************************************************************
|
1995 |
-->
|
1996 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
1997 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
1998 |
<tr style='mso-yfti-irow:0'>
|
1999 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2000 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2001 |
Arial'>32. C++ header files should have the extension <i>.hpp</i>. Source
|
2002 |
files can have the extension <i>.</i>cpp (recommend), .cc, .c++ or .C. <o:p>And all of the file names shold be capitalized.</o:p></span></b></p>
|
2003 |
</td>
|
2004 |
</tr>
|
2005 |
<tr style='mso-yfti-irow:1'>
|
2006 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2007 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>MyClass.hpp</span></tt></p>
|
2008 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>MyClass.cpp </span></tt><span lang=EN-US style='font-size:10.0pt;
|
2009 |
font-family:Arial'><o:p></o:p></span></p></td>
|
2010 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>myClass.hpp</span></tt></p>
|
2011 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>myClass.cpp </span></tt><span lang=EN-US style='font-size:10.0pt;
|
2012 |
font-family:Arial'><o:p></o:p></span></p></td>
|
2013 |
</tr>
|
2014 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2015 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2016 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2017 |
Arial'>These are all accepted C++ standards for file extension. <o:p></o:p></span></p>
|
2018 |
</td>
|
2019 |
</tr>
|
2020 |
</table>
|
2021 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2022 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2023 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2024 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2025 |
<tr style='mso-yfti-irow:0'>
|
2026 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2027 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2028 |
Arial'><!--
|
2029 |
****************************************************************************
|
2030 |
Rule
|
2031 |
****************************************************************************
|
2032 |
-->33. A class should be declared in a header file and defined in a source file
|
2033 |
where the <span class=GramE>name of the files match</span> the name of the
|
2034 |
class. <o:p></o:p></span></b></p>
|
2035 |
</td>
|
2036 |
</tr>
|
2037 |
<tr style='mso-yfti-irow:1'>
|
2038 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2039 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>MyClass.hpp,
|
2040 |
MyClass.cpp</span></tt><span lang=EN-US style='font-size:10.0pt;
|
2041 |
font-family:Arial'><o:p></o:p></span></p>
|
2042 |
</td>
|
2043 |
</tr>
|
2044 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2045 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2046 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2047 |
Arial'>Makes it easy to find the associated files of a given class. This
|
2048 |
convention is enforced in Java and has become very successful as such. <o:p></o:p></span></p>
|
2049 |
</td>
|
2050 |
</tr>
|
2051 |
</table>
|
2052 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2053 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2054 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2055 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2056 |
<tr style='mso-yfti-irow:0'>
|
2057 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2058 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2059 |
Arial'><!--
|
2060 |
****************************************************************************
|
2061 |
Rule
|
2062 |
****************************************************************************
|
2063 |
-->34. All definitions should reside in source files. <o:p></o:p></span></b></p>
|
2064 |
</td>
|
2065 |
</tr>
|
2066 |
<tr style='mso-yfti-irow:1'>
|
2067 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2068 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>class
|
2069 |
MyClass </span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
2070 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
2071 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{ </span></tt><br>
|
2072 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2073 |
public: </span></tt><br>
|
2074 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2075 |
int getValue () {return value_;} // NO! </span></tt><br>
|
2076 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2077 |
... </span></tt><br>
|
2078 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2079 |
private: </span></tt><br>
|
2080 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2081 |
int value_; </span></tt><br>
|
2082 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span
|
2083 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2084 |
</td>
|
2085 |
</tr>
|
2086 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2087 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2088 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2089 |
Arial'>The header files should declare an <span class=GramE>interface,</span>
|
2090 |
the source file should implement it. When looking for an implementation,
|
2091 |
the programmer should always know that it is found in the source file. The
|
2092 |
obvious exception to this rule is of course inline functions that must be
|
2093 |
defined in the header file. <o:p></o:p></span></p>
|
2094 |
</td>
|
2095 |
</tr>
|
2096 |
</table>
|
2097 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2098 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2099 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2100 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2101 |
<tr style='mso-yfti-irow:0'>
|
2102 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2103 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2104 |
Arial'><!--
|
2105 |
****************************************************************************
|
2106 |
Rule
|
2107 |
****************************************************************************
|
2108 |
-->35. File content must be kept within 80 columns. <o:p></o:p></span></b></p>
|
2109 |
</td>
|
2110 |
</tr>
|
2111 |
<tr style='mso-yfti-irow:1'>
|
2112 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2113 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2114 |
Arial'><o:p> </o:p></span></p>
|
2115 |
</td>
|
2116 |
</tr>
|
2117 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2118 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2119 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2120 |
Arial'>80 columns is a common dimension for editors, terminal emulators,
|
2121 |
printers and debuggers, and files that are shared between several people
|
2122 |
should keep within these constraints. It improves readability when
|
2123 |
unintentional line breaks are avoided when passing a file between
|
2124 |
programmers. <o:p></o:p></span></p>
|
2125 |
</td>
|
2126 |
</tr>
|
2127 |
</table>
|
2128 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2129 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2130 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2131 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2132 |
<tr style='mso-yfti-irow:0'>
|
2133 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2134 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2135 |
Arial'><!--
|
2136 |
****************************************************************************
|
2137 |
Rule
|
2138 |
****************************************************************************
|
2139 |
-->36. Special characters like TAB and page break must be avoided. <o:p></o:p></span></b></p>
|
2140 |
</td>
|
2141 |
</tr>
|
2142 |
<tr style='mso-yfti-irow:1'>
|
2143 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2144 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2145 |
Arial'><o:p> </o:p></span></p>
|
2146 |
</td>
|
2147 |
</tr>
|
2148 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2149 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2150 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2151 |
Arial'>These characters are bound to cause problem for editors, printers,
|
2152 |
terminal emulators or debuggers when used in a multi-programmer,
|
2153 |
multi-platform environment. <o:p> Xemacs inserts hard TAB into files which should be avoided </o:p></span></p>
|
2154 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2155 |
Arial'><o:p></o:p></span></p>
|
2156 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2157 |
Arial'><o:p><span class="style1"> Indent everything to 4 spaces </span></o:p></span></p></td>
|
2158 |
</tr>
|
2159 |
</table>
|
2160 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2161 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2162 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2163 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2164 |
<tr style='mso-yfti-irow:0'>
|
2165 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2166 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2167 |
Arial'><!--
|
2168 |
****************************************************************************
|
2169 |
Rule
|
2170 |
****************************************************************************
|
2171 |
-->37. The incompleteness of split lines must be made obvious [1]. <o:p></o:p></span></b></p>
|
2172 |
</td>
|
2173 |
</tr>
|
2174 |
<tr style='mso-yfti-irow:1'>
|
2175 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2176 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>totalSum =
|
2177 |
a + b + c +</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
2178 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
2179 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2180 |
d + e;</span></tt><br>
|
2181 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>function
|
2182 |
(param1, param2,</span></tt><br>
|
2183 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2184 |
param3);</span></tt><br>
|
2185 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>setText
|
2186 |
("Long line split"</span></tt><br>
|
2187 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2188 |
"into two parts.");</span></tt><br>
|
2189 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for
|
2190 |
(tableNo = 0; tableNo < nTables;</span></tt><br>
|
2191 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2192 |
tableNo += tableStep) </span></tt></span><span lang=EN-US style='font-size:
|
2193 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2194 |
</td>
|
2195 |
</tr>
|
2196 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2197 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2198 |
<p class=MsoNormal><st1:City><st1:place><span lang=EN-US style='font-size:
|
2199 |
7.5pt;font-family:Arial'>Split</span></st1:place></st1:City><span
|
2200 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> lines occurs when a
|
2201 |
statement exceed the 80 column limit given above. It is difficult to give
|
2202 |
rigid rules for how lines should be split, but the examples above should
|
2203 |
give a general hint. <o:p></o:p></span></p>
|
2204 |
<p><span lang=EN-US>In general: </span></p>
|
2205 |
<ul type=disc>
|
2206 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
2207 |
auto;mso-list:l2 level1 lfo6;tab-stops:list 36.0pt'><span lang=EN-US
|
2208 |
style='font-size:10.0pt;font-family:Arial'>Break after a comma. <o:p></o:p></span></li>
|
2209 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
2210 |
auto;mso-list:l2 level1 lfo6;tab-stops:list 36.0pt'><span lang=EN-US
|
2211 |
style='font-size:10.0pt;font-family:Arial'>Break after an operator. <o:p></o:p></span></li>
|
2212 |
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:
|
2213 |
auto;mso-list:l2 level1 lfo6;tab-stops:list 36.0pt'><span lang=EN-US
|
2214 |
style='font-size:10.0pt;font-family:Arial'>Align the new line with the
|
2215 |
beginning of the expression on the previous line. <o:p></o:p></span></li>
|
2216 |
</ul>
|
2217 |
</td>
|
2218 |
</tr>
|
2219 |
</table>
|
2220 |
<h3><a name="Include_Files"></a><span lang=EN-US>4.2 Include Files and
|
2221 |
Include Statements<o:p></o:p></span></h3>
|
2222 |
<!--
|
2223 |
****************************************************************************
|
2224 |
Rule
|
2225 |
****************************************************************************
|
2226 |
-->
|
2227 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2228 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2229 |
<tr style='mso-yfti-irow:0'>
|
2230 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2231 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2232 |
Arial'>38. Header files must include a construction that prevents multiple <span
|
2233 |
class=GramE>inclusion</span>. The convention is an all uppercase
|
2234 |
construction of the module name, the file name and the hpp suffix. <o:p></o:p></span></b></p>
|
2235 |
</td>
|
2236 |
</tr>
|
2237 |
<tr style='mso-yfti-irow:1'>
|
2238 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2239 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>#ifndef MOD_FILENAME_H</span></tt><span
|
2240 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2241 |
"Courier New"'>PP<br>
|
2242 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#define
|
2243 |
MOD_FILENAME_H</span></tt>PP<br>
|
2244 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> :</span></tt><br>
|
2245 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#endif
|
2246 |
</span></tt></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
2247 |
Arial'><o:p></o:p></span></p>
|
2248 |
</td>
|
2249 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>#ifndef _MOD_FILENAME_H</span></tt><span
|
2250 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2251 |
"Courier New"'>PP_<br>
|
2252 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#define _MOD_FILENAME_H</span></tt>PP_<br>
|
2253 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> :</span></tt><br>
|
2254 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#endif </span></tt></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
2255 |
Arial'><o:p></o:p></span></span></td>
|
2256 |
</tr>
|
2257 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2258 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2259 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2260 |
Arial'>The construction is to avoid compilation errors. The name convention
|
2261 |
is common practice. The construction should appear in the top of the file
|
2262 |
(before the file header) so file parsing is aborted immediately and
|
2263 |
compilation time is reduced. <o:p></o:p></span></p>
|
2264 |
</td>
|
2265 |
</tr>
|
2266 |
</table>
|
2267 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2268 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2269 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2270 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2271 |
<tr style='mso-yfti-irow:0'>
|
2272 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2273 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2274 |
Arial'><!--
|
2275 |
****************************************************************************
|
2276 |
Rule
|
2277 |
****************************************************************************
|
2278 |
-->39. Include statements should be sorted and grouped. Sorted by their
|
2279 |
hierarchical position in the system with low level files included first.
|
2280 |
Leave an empty line between groups of include statements. <o:p></o:p></span></b></p>
|
2281 |
</td>
|
2282 |
</tr>
|
2283 |
<tr style='mso-yfti-irow:1'>
|
2284 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2285 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>#include
|
2286 |
<fstream></span></tt><span lang=EN-US style='font-size:10.0pt;
|
2287 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
2288 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#include
|
2289 |
<iomanip></span></tt><br>
|
2290 |
<br>
|
2291 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#include
|
2292 |
<Xm/Xm.h></span></tt><br>
|
2293 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#include
|
2294 |
<Xm/ToggleB.h></span></tt><br>
|
2295 |
<br>
|
2296 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#include
|
2297 |
"ui/PropertiesDialog.h"</span></tt><br>
|
2298 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>#include
|
2299 |
"ui/MainWindow.h" </span></tt></span><span lang=EN-US
|
2300 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2301 |
</td>
|
2302 |
</tr>
|
2303 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2304 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2305 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2306 |
Arial'>In addition to show the reader the individual include files, it also
|
2307 |
give an immediate clue about the modules that are involved. <o:p></o:p></span></p>
|
2308 |
<p><span lang=EN-US>Include file paths must never be absolute. Compiler
|
2309 |
directives should instead be used to indicate root directories for
|
2310 |
includes. </span></p>
|
2311 |
</td>
|
2312 |
</tr>
|
2313 |
</table>
|
2314 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2315 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2316 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2317 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2318 |
<tr style='mso-yfti-irow:0'>
|
2319 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2320 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2321 |
Arial'><!--
|
2322 |
****************************************************************************
|
2323 |
Rule
|
2324 |
****************************************************************************
|
2325 |
-->40. Include statements must be located at the top of a file only. <o:p></o:p></span></b></p>
|
2326 |
</td>
|
2327 |
</tr>
|
2328 |
<tr style='mso-yfti-irow:1'>
|
2329 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2330 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2331 |
Arial'><o:p> </o:p></span></p>
|
2332 |
</td>
|
2333 |
</tr>
|
2334 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2335 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2336 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2337 |
Arial'>Common practice. Avoid unwanted compilation side effects by
|
2338 |
"hidden" include statements deep into a source file. <o:p></o:p></span></p>
|
2339 |
</td>
|
2340 |
</tr>
|
2341 |
</table>
|
2342 |
<p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
2343 |
line-break'>
|
2344 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
2345 |
<![endif]></span></p>
|
2346 |
<h2><a name=Statements></a><span lang=EN-US>5 Statements</span></h2>
|
2347 |
<h3><a name=Types></a><span lang=EN-US>5.1 Types<o:p></o:p></span></h3>
|
2348 |
<!--
|
2349 |
****************************************************************************
|
2350 |
Rule
|
2351 |
****************************************************************************
|
2352 |
-->
|
2353 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2354 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2355 |
<tr style='mso-yfti-irow:0'>
|
2356 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2357 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2358 |
Arial'>41. Types that are local to one file only can be declared inside
|
2359 |
that file. <o:p></o:p></span></b></p>
|
2360 |
</td>
|
2361 |
</tr>
|
2362 |
<tr style='mso-yfti-irow:1'>
|
2363 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2364 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2365 |
Arial'><o:p> </o:p></span></p>
|
2366 |
</td>
|
2367 |
</tr>
|
2368 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2369 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2370 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2371 |
Arial'>Enforces information hiding. <o:p></o:p></span></p>
|
2372 |
</td>
|
2373 |
</tr>
|
2374 |
</table>
|
2375 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2376 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2377 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2378 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2379 |
<tr style='mso-yfti-irow:0'>
|
2380 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2381 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2382 |
Arial'><!--
|
2383 |
****************************************************************************
|
2384 |
Rule
|
2385 |
****************************************************************************
|
2386 |
-->42. The parts of a class must be sorted <i>public</i>, <i>protected </i>and <i>private</i>
|
2387 |
[2<span class=GramE>][</span>3]. All sections must be identified
|
2388 |
explicitly. Not applicable sections should be left out. <o:p></o:p></span></b></p>
|
2389 |
</td>
|
2390 |
</tr>
|
2391 |
<tr style='mso-yfti-irow:1'>
|
2392 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2393 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2394 |
Arial'><o:p> </o:p></span></p>
|
2395 |
</td>
|
2396 |
</tr>
|
2397 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2398 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2399 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2400 |
Arial'>The ordering is <i>"most public first"</i> so people who
|
2401 |
only wish to use the class can stop reading when they reach the </span><tt><span
|
2402 |
lang=EN-US style='font-size:7.5pt'>protected/private</span></tt><span
|
2403 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> sections. <o:p></o:p></span></p>
|
2404 |
</td>
|
2405 |
</tr>
|
2406 |
</table>
|
2407 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2408 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2409 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2410 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2411 |
<tr style='mso-yfti-irow:0'>
|
2412 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2413 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2414 |
Arial'><!--
|
2415 |
****************************************************************************
|
2416 |
Rule
|
2417 |
****************************************************************************
|
2418 |
-->43. Type conversions must always be done explicitly. Never rely on implicit
|
2419 |
type conversion. <o:p></o:p></span></b></p>
|
2420 |
</td>
|
2421 |
</tr>
|
2422 |
<tr style='mso-yfti-irow:1'>
|
2423 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2424 |
<p class=MsoNormal><span class=GramE><tt><span lang=EN-US style='font-size:
|
2425 |
10.0pt'>floatValue</span></tt></span><tt><span lang=EN-US style='font-size:
|
2426 |
10.0pt'> = static_cast<float> (intValue); // YES! </span></tt><span
|
2427 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2428 |
"Courier New"'><br>
|
2429 |
</span><span
|
2430 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2431 |
</td>
|
2432 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><span
|
2433 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2434 |
"Courier New"'><span class=GramE><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
2435 |
10.0pt'>floatValue</span></tt></span><tt><span style='mso-ansi-font-size:
|
2436 |
10.0pt;mso-bidi-font-size:10.0pt'> = intValue; // NO! </span></tt></span><span
|
2437 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
2438 |
</tr>
|
2439 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2440 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2441 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2442 |
Arial'>By this, the programmer indicates that he is aware of the different
|
2443 |
types involved and that the mix is intentional. <o:p></o:p></span></p>
|
2444 |
</td>
|
2445 |
</tr>
|
2446 |
</table>
|
2447 |
<h3><a name=Variables></a><span lang=EN-US>5.2 Variables<o:p></o:p></span></h3>
|
2448 |
<!--
|
2449 |
****************************************************************************
|
2450 |
Rule
|
2451 |
****************************************************************************
|
2452 |
-->
|
2453 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2454 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2455 |
<tr style='mso-yfti-irow:0'>
|
2456 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2457 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2458 |
Arial'>44. Variables should be initialized where they are declared. <o:p></o:p></span></b></p>
|
2459 |
</td>
|
2460 |
</tr>
|
2461 |
<tr style='mso-yfti-irow:1'>
|
2462 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'><p class="style4">int x = 10;
|
2463 |
</p>
|
2464 |
<p class="style4">int y = 20; </p>
|
2465 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family: fixed'><o:p> </o:p></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
2466 |
Arial'><o:p></o:p></span></p>
|
2467 |
</td>
|
2468 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class="style4 style5">int x;</p>
|
2469 |
<p class="style6">int y;</p>
|
2470 |
<p class="style6">x = 10;</p>
|
2471 |
<p class="style6">y = 20;</p> </td>
|
2472 |
</tr>
|
2473 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2474 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2475 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2476 |
Arial'>This ensures that variables are valid at any time. Sometimes it is
|
2477 |
impossible to initialize a variable to a valid value where it is declared: <o:p></o:p></span></p>
|
2478 |
<p><tt><span lang=ES style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
2479 |
10.0pt;mso-ansi-language:ES'>int x, y, z; </span></tt><span lang=ES
|
2480 |
style='font-family:fixed;mso-bidi-font-family:"Courier New";mso-ansi-language:
|
2481 |
ES'><br>
|
2482 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>getCenter
|
2483 |
(&x, &y, &z); </span></tt></span><span lang=ES
|
2484 |
style='mso-ansi-language:ES'><o:p></o:p></span></p>
|
2485 |
<p><span lang=EN-US>In these cases it should be left uninitialized rather
|
2486 |
than initialized to some phony value. </span></p>
|
2487 |
</td>
|
2488 |
</tr>
|
2489 |
</table>
|
2490 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2491 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2492 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2493 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2494 |
<tr style='mso-yfti-irow:0'>
|
2495 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2496 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2497 |
Arial'><!--
|
2498 |
****************************************************************************
|
2499 |
Rule
|
2500 |
****************************************************************************
|
2501 |
-->45. Variables must never have dual meaning. <o:p></o:p></span></b></p>
|
2502 |
</td>
|
2503 |
</tr>
|
2504 |
<tr style='mso-yfti-irow:1'>
|
2505 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2506 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2507 |
Arial'><o:p> </o:p></span></p>
|
2508 |
</td>
|
2509 |
</tr>
|
2510 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2511 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2512 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2513 |
Arial'>Enhance readability by ensuring all concepts are represented
|
2514 |
uniquely. Reduce chance of error by side effects. <o:p></o:p></span></p>
|
2515 |
</td>
|
2516 |
</tr>
|
2517 |
</table>
|
2518 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2519 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2520 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2521 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2522 |
<tr style='mso-yfti-irow:0'>
|
2523 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2524 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2525 |
Arial'><!--
|
2526 |
****************************************************************************
|
2527 |
Rule
|
2528 |
****************************************************************************
|
2529 |
-->46. Use of global variables should be minimized. <o:p></o:p></span></b></p>
|
2530 |
</td>
|
2531 |
</tr>
|
2532 |
<tr style='mso-yfti-irow:1'>
|
2533 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2534 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2535 |
Arial'><o:p> </o:p></span></p>
|
2536 |
</td>
|
2537 |
</tr>
|
2538 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2539 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2540 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2541 |
Arial'>In C++ there <span class=GramE>is no reason global variables</span>
|
2542 |
need to be used at all. The same is true for global functions or file scope
|
2543 |
(static) variables. <o:p></o:p></span></p>
|
2544 |
</td>
|
2545 |
</tr>
|
2546 |
</table>
|
2547 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2548 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2549 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2550 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2551 |
<tr style='mso-yfti-irow:0'>
|
2552 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2553 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2554 |
Arial'><!--
|
2555 |
****************************************************************************
|
2556 |
Rule
|
2557 |
****************************************************************************
|
2558 |
-->47. Class variables should never be declared public. <o:p></o:p></span></b></p>
|
2559 |
</td>
|
2560 |
</tr>
|
2561 |
<tr style='mso-yfti-irow:1'>
|
2562 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2563 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2564 |
Arial'><o:p> </o:p></span></p>
|
2565 |
</td>
|
2566 |
</tr>
|
2567 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2568 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2569 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2570 |
Arial'>The concept of C++ information hiding and encapsulation is violated
|
2571 |
by public variables. Use private variables and access functions instead.
|
2572 |
One exception to this rule is when the class is essentially a data
|
2573 |
structure, with no behavior (equivalent to a C </span><tt><span lang=EN-US
|
2574 |
style='font-size:7.5pt'>struct</span></tt><span lang=EN-US
|
2575 |
style='font-size:7.5pt;font-family:Arial'>). In this case it is appropriate
|
2576 |
to make the class' instance variables public [2]. <o:p></o:p></span></p>
|
2577 |
<p><span lang=EN-US>Note that <i>struct</i>s are kept in C++ for
|
2578 |
compatibility with C only, and avoiding them increases the readability of
|
2579 |
the code by reducing the number of constructs used. Use a class instead. </span></p>
|
2580 |
</td>
|
2581 |
</tr>
|
2582 |
</table>
|
2583 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2584 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2585 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2586 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2587 |
<tr style='mso-yfti-irow:0'>
|
2588 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2589 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2590 |
Arial'><!--
|
2591 |
****************************************************************************
|
2592 |
Rule
|
2593 |
****************************************************************************
|
2594 |
-->48. Related variables of the same type can be declared in a common statement
|
2595 |
[3].<br>
|
2596 |
Unrelated variables should not be declared in the same statement. <o:p></o:p></span></b></p>
|
2597 |
</td>
|
2598 |
</tr>
|
2599 |
<tr style='mso-yfti-irow:1'>
|
2600 |
<td bordercolor="#ECE9D8" style='padding:.75pt .75pt .75pt .75pt'>
|
2601 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>float
|
2602 |
x, y, z;</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
2603 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
2604 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>float
|
2605 |
revenueJanuary, revenueFebruary, revenueMarch; </span></tt></span><span
|
2606 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p> </td>
|
2607 |
</tr>
|
2608 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2609 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2610 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2611 |
Arial'>The common requirement of having declarations on separate lines is
|
2612 |
not useful in the situations like the ones above. It enhances readability
|
2613 |
to group variables like this. <o:p></o:p></span></p>
|
2614 |
</td>
|
2615 |
</tr>
|
2616 |
</table>
|
2617 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2618 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2619 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2620 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2621 |
<tr style='mso-yfti-irow:0'>
|
2622 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2623 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2624 |
Arial'><!--
|
2625 |
****************************************************************************
|
2626 |
Rule
|
2627 |
****************************************************************************
|
2628 |
-->
|
2629 |
49. C++ pointers and references should have their reference symbol next<b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2630 |
Arial'> to <b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2631 |
Arial'>the variable name</span></b></span></b><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2632 |
Arial'><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2633 |
Arial'></span></b></span></b>rather than<b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2634 |
Arial'> to <b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2635 |
Arial'>the type name</span></b></span></b>[3]. <o:p></o:p></span></b></p> </td>
|
2636 |
</tr>
|
2637 |
<tr style='mso-yfti-irow:1'>
|
2638 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2639 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>float *x;</span></tt><span lang=EN-US style='font-size:10.0pt;
|
2640 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
2641 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>int &y;</span></tt></span><span
|
2642 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2643 |
</td>
|
2644 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>float* x</span></tt><span lang=EN-US style='font-size:10.0pt;
|
2645 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt>;</tt><br>
|
2646 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>int& y</span></tt></span><span
|
2647 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p>;</o:p></span></span></td>
|
2648 |
</tr>
|
2649 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2650 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2651 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2652 |
Arial'>It is debatable whether a pointer is a variable of a pointer type
|
2653 |
(float*<span class=GramE> x</span>) or a pointer to a given type
|
2654 |
(float *x). Important in the recommendation given though is the fact
|
2655 |
that it is impossible to declare more than one pointer in a given statement
|
2656 |
using the first approach. I.e. float* x, y, z; is equivalent with float *x;
|
2657 |
float y; float z; The same goes for references. <o:p></o:p></span></p>
|
2658 |
</td>
|
2659 |
</tr>
|
2660 |
</table>
|
2661 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2662 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2663 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2664 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2665 |
<tr style='mso-yfti-irow:0'>
|
2666 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2667 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2668 |
Arial'><!--
|
2669 |
****************************************************************************
|
2670 |
Rule
|
2671 |
****************************************************************************
|
2672 |
-->50. The </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>const</span></b></tt><b><span
|
2673 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> keyword should be
|
2674 |
listed before the type name. <o:p></o:p></span></b></p>
|
2675 |
</td>
|
2676 |
</tr>
|
2677 |
<tr style='mso-yfti-irow:1'>
|
2678 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2679 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>void f1
|
2680 |
(const Widget *v); </span></tt><span
|
2681 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2682 |
</td>
|
2683 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>void f1 (Widget const *v); </span></tt></span></td>
|
2684 |
</tr>
|
2685 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2686 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2687 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2688 |
Arial'>Neither is better nor worse, but since the former is more commonly
|
2689 |
used that should be the convention. <o:p></o:p></span></p>
|
2690 |
</td>
|
2691 |
</tr>
|
2692 |
</table>
|
2693 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2694 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2695 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2696 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2697 |
<tr style='mso-yfti-irow:0'>
|
2698 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2699 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2700 |
Arial'><!--
|
2701 |
****************************************************************************
|
2702 |
Rule
|
2703 |
****************************************************************************
|
2704 |
-->51. Implicit test for <i>0</i> should not be used other than for boolean
|
2705 |
variables. <o:p></o:p></span></b></p>
|
2706 |
</td>
|
2707 |
</tr>
|
2708 |
<tr style='mso-yfti-irow:1'>
|
2709 |
<td width="51%" style='padding:.75pt .75pt .75pt .75pt'>
|
2710 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>if (nLines
|
2711 |
!= 0)</span></tt><span
|
2712 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2713 |
"Courier New"'><br>
|
2714 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if
|
2715 |
(value != 0.0)</span></tt></span><span
|
2716 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2717 |
<p class=MsoNormal><span
|
2718 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2719 |
<p class=MsoNormal><span
|
2720 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2721 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2722 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2723 |
"Courier New"'><tt></tt></span></span></o:p></span><span
|
2724 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2725 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2726 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2727 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2728 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if (pointer != NULL)</span></tt></span><span
|
2729 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p><o:p></o:p></span></span></span></o:p></span></p>
|
2730 |
<p class=MsoNormal><span
|
2731 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2732 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2733 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2734 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2735 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if (!isBool)</span></tt></span></span></o:p></span><span
|
2736 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></o:p></span></p></td>
|
2737 |
<td width="49%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>if (nLines)</span></tt><span
|
2738 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2739 |
"Courier New"'><br>
|
2740 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if (value)</span></tt></span></span><span
|
2741 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span> <p class="MsoNormal"><span
|
2742 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2743 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2744 |
"Courier New"'><tt></tt></span><span
|
2745 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p><o:p></o:p></span></o:p></span></p>
|
2746 |
<p class="MsoNormal"><span
|
2747 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2748 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2749 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2750 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2751 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2752 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2753 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if (!pointer)</span></tt></span></span></span></o:p></span></o:p></span></o:p></span></p>
|
2754 |
<p class="MsoNormal"><span
|
2755 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2756 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2757 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p><span
|
2758 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2759 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2760 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2761 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if (<span
|
2762 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2763 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2764 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><span
|
2765 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2766 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>isBool</span></tt></span></span></span></span> != false)</span></tt></span><span
|
2767 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p><o:p></o:p></span></span></span></o:p></span></o:p></span></o:p></span></p></td>
|
2768 |
</tr>
|
2769 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2770 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2771 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2772 |
Arial'>It is not necessarily defined by the compiler that ints and floats 0
|
2773 |
are implemented as binary 0. Also, by using explicit test the statement
|
2774 |
give immediate clue of the type being tested. It is common also to suggest
|
2775 |
that pointers shouldn't test implicit for 0 either, i.e. </span><tt><span
|
2776 |
lang=EN-US style='font-size:7.5pt'>if (line == 0)</span></tt><span
|
2777 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> instead of </span><tt><span
|
2778 |
lang=EN-US style='font-size:7.5pt'>if (line)</span></tt><span lang=EN-US
|
2779 |
style='font-size:7.5pt;font-family:Arial'>. The latter is regarded as such
|
2780 |
a common practice in C/C++ however that it can be used. <o:p></o:p></span></p>
|
2781 |
</td>
|
2782 |
</tr>
|
2783 |
</table>
|
2784 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2785 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2786 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2787 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2788 |
<tr style='mso-yfti-irow:0'>
|
2789 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2790 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2791 |
Arial'><!--
|
2792 |
****************************************************************************
|
2793 |
Rule
|
2794 |
****************************************************************************
|
2795 |
-->52. Variables should be declared in the smallest scope possible. <o:p></o:p></span></b></p>
|
2796 |
</td>
|
2797 |
</tr>
|
2798 |
<tr style='mso-yfti-irow:1'>
|
2799 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2800 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2801 |
Arial'><o:p> </o:p></span></p>
|
2802 |
</td>
|
2803 |
</tr>
|
2804 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2805 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2806 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2807 |
Arial'>Keeping the operations on a variable within a small scope, it is
|
2808 |
easier to control the effects and side effects of the variable. <o:p></o:p></span></p>
|
2809 |
</td>
|
2810 |
</tr>
|
2811 |
</table>
|
2812 |
<h3><a name=Loops></a><span lang=EN-US>5.3 Loops<o:p></o:p></span></h3>
|
2813 |
<!--
|
2814 |
****************************************************************************
|
2815 |
Rule
|
2816 |
****************************************************************************
|
2817 |
-->
|
2818 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2819 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2820 |
<tr style='mso-yfti-irow:0'>
|
2821 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2822 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2823 |
Arial'>53. Only loop control statements must be included in the </span></b><span
|
2824 |
class=GramE><tt><b><span lang=EN-US style='font-size:10.0pt'>for(</span></b></tt></span><tt><b><span
|
2825 |
lang=EN-US style='font-size:10.0pt'>)</span></b></tt><b><span lang=EN-US
|
2826 |
style='font-size:10.0pt;font-family:Arial'> construction. <o:p></o:p></span></b></p>
|
2827 |
</td>
|
2828 |
</tr>
|
2829 |
<tr style='mso-yfti-irow:1'>
|
2830 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2831 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>sum = 0;</span></tt><span lang=EN-US style='font-size:
|
2832 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
2833 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for
|
2834 |
(i = 0; i < 100; i++)</span></tt><br>
|
2835 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2836 |
sum += value[i]; </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
2837 |
font-family:Arial'><o:p></o:p></span></p>
|
2838 |
</td>
|
2839 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>for (i = 0; sum = 0; i < 100; i++)</span></tt><span lang=EN-US style='font-size:
|
2840 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
2841 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> sum += value[i]; </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
2842 |
font-family:Arial'><o:p></o:p></span></span></td>
|
2843 |
</tr>
|
2844 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2845 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2846 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2847 |
Arial'>Increase maintainability and readability. Make it crystal clear what
|
2848 |
controls the loop and what the loop contains. <o:p></o:p></span></p>
|
2849 |
</td>
|
2850 |
</tr>
|
2851 |
</table>
|
2852 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2853 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2854 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2855 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2856 |
<tr style='mso-yfti-irow:0'>
|
2857 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2858 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2859 |
Arial'><!--
|
2860 |
****************************************************************************
|
2861 |
Rule
|
2862 |
****************************************************************************
|
2863 |
-->54. </span></b><st1:place><b><span lang=EN-US style='font-size:10.0pt;
|
2864 |
font-family:Arial'>Loop</span></b></st1:place><b><span lang=EN-US
|
2865 |
style='font-size:10.0pt;font-family:Arial'> variables should be initialized
|
2866 |
immediately before the loop. <o:p></o:p></span></b></p>
|
2867 |
</td>
|
2868 |
</tr>
|
2869 |
<tr style='mso-yfti-irow:1'>
|
2870 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2871 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>isDone =
|
2872 |
false; </span></tt><span
|
2873 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2874 |
"Courier New"'><br>
|
2875 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while
|
2876 |
(!isDone) {</span></tt><br>
|
2877 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
2878 |
: </span></tt><br>
|
2879 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span lang=EN-US
|
2880 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
2881 |
</td>
|
2882 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>bool isDone = false;</span></tt><span
|
2883 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
2884 |
"Courier New"'><br>
|
2885 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>:</span></tt><br>
|
2886 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while (!isDone) {</span></tt><br>
|
2887 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>:</span></tt><br>
|
2888 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span lang=EN-US
|
2889 |
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
2890 |
</tr>
|
2891 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2892 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
2893 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2894 |
Arial'><o:p> </o:p></span></p>
|
2895 |
</td>
|
2896 |
</tr>
|
2897 |
</table>
|
2898 |
<p style='margin:0cm;margin-bottom:.0001pt'><!--
|
2899 |
****************************************************************************
|
2900 |
Rule
|
2901 |
****************************************************************************
|
2902 |
--><span lang=EN-US style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2903 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2904 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2905 |
<tr style='mso-yfti-irow:0'>
|
2906 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2907 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2908 |
Arial'>55. </span></b><span class=GramE><tt><b><span lang=EN-US
|
2909 |
style='font-size:10.0pt'>do-</span></b></tt></span><tt><b><span lang=EN-US
|
2910 |
style='font-size:10.0pt'>while</span></b></tt><b><span lang=EN-US
|
2911 |
style='font-size:10.0pt;font-family:Arial'> loops can be avoided. <o:p></o:p></span></b></p>
|
2912 |
</td>
|
2913 |
</tr>
|
2914 |
<tr style='mso-yfti-irow:1'>
|
2915 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2916 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2917 |
Arial'><o:p> </o:p></span></p>
|
2918 |
</td>
|
2919 |
</tr>
|
2920 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2921 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2922 |
<p class=MsoNormal><span class=GramE><tt><span lang=EN-US style='font-size:
|
2923 |
7.5pt'>do-</span></tt></span><tt><span lang=EN-US style='font-size:7.5pt'>while</span></tt><span
|
2924 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> loops are less
|
2925 |
readable than ordinary </span><tt><span lang=EN-US style='font-size:7.5pt'>while</span></tt><span
|
2926 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> loops and </span><tt><span
|
2927 |
lang=EN-US style='font-size:7.5pt'>for</span></tt><span lang=EN-US
|
2928 |
style='font-size:7.5pt;font-family:Arial'> loops since the conditional is
|
2929 |
at the bottom of the loop. The reader must scan the entire loop in order to
|
2930 |
understand the scope of the loop. <o:p></o:p></span></p>
|
2931 |
<p><span lang=EN-US>In addition, </span><tt><span lang=EN-US
|
2932 |
style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>do-while</span></tt><span
|
2933 |
lang=EN-US> loops are not needed. Any </span><tt><span lang=EN-US
|
2934 |
style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>do-while</span></tt><span
|
2935 |
lang=EN-US> loop can easily be rewritten into a </span><tt><span
|
2936 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while</span></tt><span
|
2937 |
lang=EN-US> loop or <span class=GramE>a <tt><span style='mso-ansi-font-size:
|
2938 |
10.0pt;mso-bidi-font-size:10.0pt'>for</span></tt></span> loop. Reducing the
|
2939 |
number of constructs used enhance readbility. </span></p>
|
2940 |
</td>
|
2941 |
</tr>
|
2942 |
</table>
|
2943 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2944 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2945 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2946 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2947 |
<tr style='mso-yfti-irow:0'>
|
2948 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2949 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2950 |
Arial'><!--
|
2951 |
****************************************************************************
|
2952 |
Rule
|
2953 |
****************************************************************************
|
2954 |
-->56. The use of </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>break</span></b></tt><b><span
|
2955 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> and </span></b><tt><b><span
|
2956 |
lang=EN-US style='font-size:10.0pt'>continue</span></b></tt><b><span
|
2957 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> in loops should be
|
2958 |
avoided. <o:p></o:p></span></b></p>
|
2959 |
</td>
|
2960 |
</tr>
|
2961 |
<tr style='mso-yfti-irow:1'>
|
2962 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2963 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
2964 |
Arial'><o:p> </o:p></span></p>
|
2965 |
</td>
|
2966 |
</tr>
|
2967 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
2968 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
2969 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
2970 |
Arial'>These constructs can be compared to goto and they should only be
|
2971 |
used if they prove to have higher readability than their structured
|
2972 |
counterpart. <o:p></o:p></span></p>
|
2973 |
</td>
|
2974 |
</tr>
|
2975 |
</table>
|
2976 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
2977 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
2978 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
2979 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
2980 |
<tr style='mso-yfti-irow:0'>
|
2981 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
2982 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
2983 |
Arial'><!--
|
2984 |
****************************************************************************
|
2985 |
Rule
|
2986 |
****************************************************************************
|
2987 |
-->57. The form </span></b><span class=GramE><tt><b><span lang=EN-US
|
2988 |
style='font-size:10.0pt'>while(</span></b></tt></span><tt><b><span
|
2989 |
lang=EN-US style='font-size:10.0pt'>true)</span></b></tt><b><span
|
2990 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> should be used for
|
2991 |
infinite loops. <o:p></o:p></span></b></p>
|
2992 |
</td>
|
2993 |
</tr>
|
2994 |
<tr style='mso-yfti-irow:1'>
|
2995 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
2996 |
<p class=MsoNormal><span class=GramE><tt><span lang=EN-US style='font-size:
|
2997 |
10.0pt'>while</span></tt></span><tt><span lang=EN-US style='font-size:10.0pt'>
|
2998 |
(true) {</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
2999 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
3000 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3001 |
: </span></tt><br>
|
3002 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt><br>
|
3003 |
</span><span
|
3004 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3005 |
</td>
|
3006 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><span lang=EN-US style='font-size:10.0pt;font-family:
|
3007 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
3008 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for (;;) <span class=GramE>{ /</span>/ NO!</span></tt><br>
|
3009 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> :</span></tt><br>
|
3010 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt><br>
|
3011 |
<br>
|
3012 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while (1) { // NO!</span></tt><br>
|
3013 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> :</span></tt><br>
|
3014 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3015 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
3016 |
</tr>
|
3017 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3018 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
3019 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3020 |
Arial'>Testing against 1 is neither necessary nor meaningful. The form </span><tt><span
|
3021 |
lang=EN-US style='font-size:7.5pt'>for (;;)</span></tt><span lang=EN-US
|
3022 |
style='font-size:7.5pt;font-family:Arial'> is not very readable, and it is
|
3023 |
not apparent that this actually is an infinite loop. <o:p></o:p></span></p>
|
3024 |
</td>
|
3025 |
</tr>
|
3026 |
</table>
|
3027 |
<h3><a name=Conditionals></a><span lang=EN-US>5.4 Conditionals<o:p></o:p></span></h3>
|
3028 |
<!--
|
3029 |
****************************************************************************
|
3030 |
Rule
|
3031 |
****************************************************************************
|
3032 |
-->
|
3033 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3034 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3035 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3036 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3037 |
<tr style='mso-yfti-irow:0'>
|
3038 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3039 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3040 |
Arial'><!--
|
3041 |
****************************************************************************
|
3042 |
Rule
|
3043 |
****************************************************************************
|
3044 |
-->58. The nominal case should be put in the <i>if</i>-part and the exception
|
3045 |
in the <i>else</i>-part of <span class=GramE>an if</span> statement [1]. <o:p></o:p></span></b></p>
|
3046 |
</td>
|
3047 |
</tr>
|
3048 |
<tr style='mso-yfti-irow:1'>
|
3049 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3050 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>isError =
|
3051 |
readFile (fileName);</span></tt><span lang=EN-US style='font-size:10.0pt;
|
3052 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3053 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if
|
3054 |
(!isError) {</span></tt><br>
|
3055 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3056 |
:</span></tt><br>
|
3057 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} else
|
3058 |
{</span></tt><br>
|
3059 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3060 |
:</span></tt><br>
|
3061 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span
|
3062 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3063 |
</td>
|
3064 |
</tr>
|
3065 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3066 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3067 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3068 |
Arial'>Makes sure that the exceptions don't obscure the normal path of
|
3069 |
execution. This is important for both the readability and performance. <o:p></o:p></span></p>
|
3070 |
</td>
|
3071 |
</tr>
|
3072 |
</table>
|
3073 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3074 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3075 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3076 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3077 |
<tr style='mso-yfti-irow:0'>
|
3078 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3079 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3080 |
Arial'><!--
|
3081 |
****************************************************************************
|
3082 |
Rule
|
3083 |
****************************************************************************
|
3084 |
-->59. The conditional should be put on a separate line. <o:p></o:p></span></b></p>
|
3085 |
</td>
|
3086 |
</tr>
|
3087 |
<tr style='mso-yfti-irow:1'>
|
3088 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
3089 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>if
|
3090 |
(isDone) </span></tt><span lang=EN-US
|
3091 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3092 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3093 |
doCleanup(); </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
3094 |
font-family:Arial'><o:p></o:p></span></p>
|
3095 |
</td>
|
3096 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'> if (isDone) doCleanup();</span></tt><span lang=EN-US
|
3097 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'></span></span></td>
|
3098 |
</tr>
|
3099 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3100 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
3101 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3102 |
Arial'>This is for debugging purposes. When writing on a single line, it is
|
3103 |
not apparent whether the test is really true or not. <o:p></o:p></span></p>
|
3104 |
</td>
|
3105 |
</tr>
|
3106 |
</table>
|
3107 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3108 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3109 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3110 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3111 |
<tr style='mso-yfti-irow:0'>
|
3112 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3113 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3114 |
Arial'><!--
|
3115 |
****************************************************************************
|
3116 |
Rule
|
3117 |
****************************************************************************
|
3118 |
-->60. Executable statements in conditionals must be avoided. <o:p></o:p></span></b></p>
|
3119 |
</td>
|
3120 |
</tr>
|
3121 |
<tr style='mso-yfti-irow:1'>
|
3122 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
3123 |
<p class=MsoNormal><span
|
3124 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3125 |
"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>fileHandle
|
3126 |
= open (fileName, "w");</span></tt><br>
|
3127 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if
|
3128 |
(!fileHandle) {</span></tt><br>
|
3129 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3130 |
:</span></tt><br>
|
3131 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3132 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3133 |
</td>
|
3134 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><span
|
3135 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3136 |
"Courier New"'><span class=GramE><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
3137 |
10.0pt'>if</span></tt></span><tt><span style='mso-ansi-font-size:10.0pt;
|
3138 |
mso-bidi-font-size:10.0pt'> (!(fileHandle = open (fileName, "w"))) { </span></tt><br>
|
3139 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> : </span></tt><br>
|
3140 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span></span></td>
|
3141 |
</tr>
|
3142 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3143 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
3144 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3145 |
Arial'>Conditionals with executable statements are just very difficult to
|
3146 |
read. This is especially true for programmers new to C/C++. <o:p></o:p></span></p>
|
3147 |
</td>
|
3148 |
</tr>
|
3149 |
</table>
|
3150 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3151 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3152 |
<p style='margin:0cm'> </p>
|
3153 |
<p style='margin:0cm'><span lang=EN-US
|
3154 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3155 |
<h3 style='margin:0cm'><a name=Template id="Template"></a><span lang=EN-US>5.5 Template </span></h3>
|
3156 |
<p style='margin:0cm'><span lang=EN-US><o:p> </o:p></span></p>
|
3157 |
<!--
|
3158 |
****************************************************************************
|
3159 |
Rule
|
3160 |
****************************************************************************
|
3161 |
--> <p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3162 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3163 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3164 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3165 |
<tr style='mso-yfti-irow:0'>
|
3166 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3167 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3168 |
Arial'>61. </span></b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3169 |
Arial'><em>typename</em></span><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3170 |
Arial'> instead of </span></b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3171 |
Arial'><em>class</em></span><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3172 |
Arial'> should be used in template <o:p>declaration</o:p></span></b></p></td>
|
3173 |
</tr>
|
3174 |
<tr style='mso-yfti-irow:1'>
|
3175 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
3176 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3177 |
Arial'><o:p></o:p></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
3178 |
Arial'><o:p><span
|
3179 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3180 |
"Courier New"'>template <typename T></span></o:p></span></p>
|
3181 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3182 |
Arial'><o:p><span
|
3183 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3184 |
"Courier New"'>inline const T& max (const T &a, const T &b);<br>
|
3185 |
</span><span
|
3186 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></o:p></span></p></td>
|
3187 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class="MsoNormal"><span lang=EN-US style='font-size:10.0pt;font-family:
|
3188 |
Arial'><span
|
3189 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3190 |
"Courier New"'>template <class T></span></span></p>
|
3191 |
<p class="MsoNormal"><span lang=EN-US style='font-size:10.0pt;font-family:
|
3192 |
Arial'><span
|
3193 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3194 |
"Courier New"'>inline const T& max (const T &a, const T &b);</span></span></p></td>
|
3195 |
</tr>
|
3196 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3197 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
3198 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3199 |
Arial'>Semantically there is no difference in this context. So, even if you use class here, any type may be used for template arguments. However, because this use of class can be misleading (not only class types can be substituted for T ). Thus, we prefer the use of typename in this context.<o:p></o:p></span></p>
|
3200 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3201 |
Arial'><o:p></o:p></span></p>
|
3202 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3203 |
Arial'><o:p><span class="style4"> template <typename T, template<T*> class Buf></span></o:p></span></p>
|
3204 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3205 |
Arial'><o:p></o:p></span><span lang=EN-US style='font-size:7.5pt'><o:p><span class="style10"> class Structure; </span></o:p></span><span lang=EN-US style='font-size:7.5pt;font-family:
|
3206 |
Arial'><o:p></o:p></span></p>
|
3207 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3208 |
Arial'><o:p><span class="style10">If template declaration involves template template parameter, use class instead<span class="style13">.</span></span></o:p></span></p></td>
|
3209 |
</tr>
|
3210 |
</table>
|
3211 |
<!--
|
3212 |
****************************************************************************
|
3213 |
Rule
|
3214 |
****************************************************************************
|
3215 |
-->
|
3216 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3217 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3218 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3219 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3220 |
<tr style='mso-yfti-irow:0'>
|
3221 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3222 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3223 |
Arial'>62. template keyword and its parameter must occ<o:p>upy at least one line </o:p></span></b></p></td>
|
3224 |
</tr>
|
3225 |
<tr style='mso-yfti-irow:1'>
|
3226 |
<td width="50%" style='padding:.75pt .75pt .75pt .75pt'>
|
3227 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3228 |
Arial'><o:p><span class="style4"> template<typename T></span></o:p></span></p>
|
3229 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3230 |
Arial'><o:p><span class="style4">somefunc(T);</span></o:p></span></p></td>
|
3231 |
<td width="50%" bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3232 |
Arial'><o:p><span class="style4">template<typename T></span></o:p> </span><span lang=EN-US style='font-size:10.0pt;font-family:
|
3233 |
Arial'><o:p><span class="style4">somefunc(T);</span></o:p></span></p> </td>
|
3234 |
</tr>
|
3235 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3236 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
3237 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3238 |
Arial'><o:p></o:p></span></p></td>
|
3239 |
</tr>
|
3240 |
</table>
|
3241 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3242 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3243 |
<p style='margin:0cm'> </p>
|
3244 |
<p style='margin:0cm'><span lang=EN-US
|
3245 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3246 |
<h3 style='margin:0cm'><a name=Misc></a><span lang=EN-US>5.6 Miscellaneous<o:p></o:p></span></h3> <!--
|
3247 |
****************************************************************************
|
3248 |
Rule
|
3249 |
****************************************************************************
|
3250 |
-->
|
3251 |
<p style='margin:0cm;margin-bottom:.0001pt'> </p>
|
3252 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3253 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3254 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3255 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3256 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3257 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3258 |
<tr style='mso-yfti-irow:0'>
|
3259 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3260 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3261 |
Arial'>63. The use of magic numbers in the code should be avoided. Numbers other than <i>0 </i>and <i>1 </i>should be considered declared as named constants instead. <o:p></o:p></span></b></p></td>
|
3262 |
</tr>
|
3263 |
<tr style='mso-yfti-irow:1'>
|
3264 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3265 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3266 |
Arial'><o:p> </o:p></span></p></td>
|
3267 |
</tr>
|
3268 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3269 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3270 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3271 |
Arial'>If the number does not have an obvious meaning by itself, the readability is enhanced by introducing a named constant instead. A different approach is to introduce a method from which the constant can be accessed. <o:p></o:p></span></p></td>
|
3272 |
</tr>
|
3273 |
</table> <p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3274 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3275 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3276 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3277 |
<tr style='mso-yfti-irow:0'>
|
3278 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3279 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3280 |
Arial'>64. Floating point constants should always be written with decimal
|
3281 |
point and at least one decimal. <o:p></o:p></span></b></p>
|
3282 |
</td>
|
3283 |
</tr>
|
3284 |
<tr style='mso-yfti-irow:1'>
|
3285 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3286 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>double
|
3287 |
total = 0.0; // NOT: double total = 0; </span></tt><span lang=EN-US
|
3288 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3289 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>double
|
3290 |
speed = 3.0e8; // NOT: double speed = 3e8;</span></tt><br>
|
3291 |
<br>
|
3292 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>double
|
3293 |
sum;</span></tt><br>
|
3294 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>:</span></tt><br>
|
3295 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>sum =
|
3296 |
(a + b) * 10.0; </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
3297 |
font-family:Arial'><o:p></o:p></span></p>
|
3298 |
</td>
|
3299 |
</tr>
|
3300 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3301 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3302 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3303 |
Arial'>This empasize the different nature of integer and floating point
|
3304 |
numbers even if their values might happen to be the same in a specific case.
|
3305 |
<o:p></o:p></span></p>
|
3306 |
<p><span lang=EN-US>Also, as in the last example above, it <span
|
3307 |
class=GramE>emphasize</span> the type of the assigned variable (</span><tt><span
|
3308 |
lang=EN-US style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>sum</span></tt><span
|
3309 |
lang=EN-US>) at a point in the code where this might not be evident. </span></p>
|
3310 |
</td>
|
3311 |
</tr>
|
3312 |
</table>
|
3313 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3314 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3315 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3316 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3317 |
<tr style='mso-yfti-irow:0'>
|
3318 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3319 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3320 |
Arial'><!--
|
3321 |
****************************************************************************
|
3322 |
Rule
|
3323 |
****************************************************************************
|
3324 |
-->65. Floating point constants should always be written with a digit before
|
3325 |
the decimal point. <o:p></o:p></span></b></p>
|
3326 |
</td>
|
3327 |
</tr>
|
3328 |
<tr style='mso-yfti-irow:1'>
|
3329 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3330 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>double
|
3331 |
total = 0.5; // NOT: double total = .5; </span></tt><span
|
3332 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3333 |
</td>
|
3334 |
</tr>
|
3335 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3336 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3337 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3338 |
Arial'>The number and expression system in C++ is borrowed from mathematics
|
3339 |
and one should adhere to mathematical conventions for syntax wherever
|
3340 |
possible. Also, 0.5 is a lot more readable than .5; There is no way it can
|
3341 |
be mixed with the integer 5. <o:p></o:p></span></p>
|
3342 |
</td>
|
3343 |
</tr>
|
3344 |
</table>
|
3345 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3346 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3347 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3348 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3349 |
<tr style='mso-yfti-irow:0'>
|
3350 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3351 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3352 |
Arial'><!--
|
3353 |
****************************************************************************
|
3354 |
Rule
|
3355 |
****************************************************************************
|
3356 |
-->66. Functions must always have the return value explicitly listed. <o:p></o:p></span></b></p>
|
3357 |
</td>
|
3358 |
</tr>
|
3359 |
<tr style='mso-yfti-irow:1'>
|
3360 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3361 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>int
|
3362 |
getValue() { // NOT: getValue()</span></tt><span lang=EN-US
|
3363 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3364 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3365 |
:</span></tt><br>
|
3366 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3367 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3368 |
</td>
|
3369 |
</tr>
|
3370 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3371 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3372 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3373 |
Arial'>If not exlicitly listed, C++ implies </span><tt><span lang=EN-US
|
3374 |
style='font-size:7.5pt'>int</span></tt><span lang=EN-US style='font-size:
|
3375 |
7.5pt;font-family:Arial'> return value for functions. A programmer must
|
3376 |
never rely on this feature, since this might be confusing for programmers
|
3377 |
not aware of this artifact. <o:p></o:p></span></p>
|
3378 |
</td>
|
3379 |
</tr>
|
3380 |
</table>
|
3381 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3382 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3383 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3384 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3385 |
<tr style='mso-yfti-irow:0'>
|
3386 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3387 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3388 |
Arial'><!--
|
3389 |
****************************************************************************
|
3390 |
Rule
|
3391 |
****************************************************************************
|
3392 |
-->67. </span></b><span class=GramE><tt><b><span lang=EN-US style='font-size:
|
3393 |
10.0pt'>goto</span></b></tt></span><b><span lang=EN-US style='font-size:
|
3394 |
10.0pt;font-family:Arial'> should not be used. <o:p></o:p></span></b></p>
|
3395 |
</td>
|
3396 |
</tr>
|
3397 |
<tr style='mso-yfti-irow:1'>
|
3398 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3399 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3400 |
Arial'><o:p> </o:p></span></p>
|
3401 |
</td>
|
3402 |
</tr>
|
3403 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3404 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3405 |
<p class=MsoNormal><span class=GramE><span lang=EN-US style='font-size:
|
3406 |
7.5pt;font-family:Arial'>Goto statements violates</span></span><span
|
3407 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> the idea of
|
3408 |
structured code. Only in some very few cases (for instance breaking out of
|
3409 |
deeply nested structures) should goto be considered, and only if the
|
3410 |
alternative structured counterpart is proven to be less readable. <o:p></o:p></span></p>
|
3411 |
</td>
|
3412 |
</tr>
|
3413 |
</table>
|
3414 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3415 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3416 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3417 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3418 |
<tr style='mso-yfti-irow:0'>
|
3419 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3420 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3421 |
Arial'><!--
|
3422 |
****************************************************************************
|
3423 |
Rule
|
3424 |
****************************************************************************
|
3425 |
-->68. "0" should be used instead of "NULL". <o:p></o:p></span></b></p>
|
3426 |
</td>
|
3427 |
</tr>
|
3428 |
<tr style='mso-yfti-irow:1'>
|
3429 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3430 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
3431 |
Arial'><o:p> </o:p></span></p>
|
3432 |
</td>
|
3433 |
</tr>
|
3434 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3435 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3436 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:7.5pt'>NULL</span></tt><span
|
3437 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'>is part of the
|
3438 |
standard C library, but is made obsolete in C++. <o:p></o:p></span></p>
|
3439 |
</td>
|
3440 |
</tr>
|
3441 |
</table>
|
3442 |
<p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
3443 |
line-break'>
|
3444 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
3445 |
<![endif]></span></p>
|
3446 |
<h2><a name="Layout_and_Comments"></a><span lang=EN-US>6 Layout and White Space </span></h2>
|
3447 |
<h3><a name=Layout></a><span lang=EN-US>6.1 Layout<o:p></o:p></span></h3>
|
3448 |
<!--
|
3449 |
****************************************************************************
|
3450 |
Rule
|
3451 |
****************************************************************************
|
3452 |
-->
|
3453 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3454 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3455 |
<tr style='mso-yfti-irow:0'>
|
3456 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3457 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3458 |
Arial'>69. Basic indentation should be 4. <o:p></o:p></span></b></p>
|
3459 |
</td>
|
3460 |
</tr>
|
3461 |
<tr style='mso-yfti-irow:1'>
|
3462 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3463 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>for (i =
|
3464 |
0; i < nElements; i++)</span></tt><span lang=EN-US style='font-size:
|
3465 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3466 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3467 |
a[i] = 0; </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
3468 |
font-family:Arial'><o:p></o:p></span></p>
|
3469 |
</td>
|
3470 |
</tr>
|
3471 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3472 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3473 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3474 |
Arial'>Indentation of 1 is <span class=GramE>to</span> small to emphasize
|
3475 |
the logical layout of the code. Indentation larger than 4 makes deeply
|
3476 |
nested code difficult to read and increase the chance that the lines must
|
3477 |
be split. Choosing between indentation of 2, 3 and 4,<span class=GramE>
|
3478 |
2</span> and 4 are the more common, <o:p> we prefer 4.</o:p></span></p>
|
3479 |
</td>
|
3480 |
</tr>
|
3481 |
</table>
|
3482 |
<!--
|
3483 |
****************************************************************************
|
3484 |
Rule
|
3485 |
****************************************************************************
|
3486 |
-->
|
3487 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3488 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3489 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3490 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3491 |
<tr style='mso-yfti-irow:0'>
|
3492 |
<td colspan=2 style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3493 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3494 |
Arial'>70. Block layout should be as illustrated in example 1 below
|
3495 |
, and must not be as shown in example 2.
|
3496 |
<o:p></o:p></span></b></p>
|
3497 |
</td>
|
3498 |
</tr>
|
3499 |
<tr style='mso-yfti-irow:1'>
|
3500 |
<td width="33%" style='width:33.0%;padding:.75pt .75pt .75pt .75pt'>
|
3501 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>while
|
3502 |
(!done) {</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
3503 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
3504 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3505 |
doSomething();</span></tt><br>
|
3506 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3507 |
done = moreToDo();</span></tt><br>
|
3508 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3509 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3510 |
</td>
|
3511 |
<td bgcolor="#FDB5A6" style='width:33.0%;padding:.75pt .75pt .75pt .75pt'>
|
3512 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>while
|
3513 |
(!done)</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
3514 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
3515 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
3516 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3517 |
doSomething();</span></tt><br>
|
3518 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3519 |
done = moreToDo();</span></tt><br>
|
3520 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3521 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3522 |
<p class=MsoNormal><span
|
3523 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>while
|
3524 |
(!done)</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
3525 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
3526 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3527 |
{</span></tt><br>
|
3528 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3529 |
doSomething();</span></tt><br>
|
3530 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3531 |
done = moreToDo();</span></tt><br>
|
3532 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3533 |
}</span></tt></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
3534 |
Arial'><o:p></o:p></span></p></td>
|
3535 |
</tr>
|
3536 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3537 |
<td colspan=2 style='padding:.75pt .75pt .75pt .75pt'>
|
3538 |
<p class=MsoNormal><span class=GramE><span lang=EN-US style='font-size:
|
3539 |
7.5pt;font-family:Arial'>Example 3 introduce</span></span><span lang=EN-US
|
3540 |
style='font-size:7.5pt;font-family:Arial'> an extra indentation level which
|
3541 |
doesn't emphasize the logical structure of the code as clearly as example 1
|
3542 |
and 2. <o:p></o:p></span></p>
|
3543 |
</td>
|
3544 |
</tr>
|
3545 |
</table>
|
3546 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3547 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3548 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3549 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3550 |
<tr style='mso-yfti-irow:0'>
|
3551 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3552 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3553 |
Arial'><!--
|
3554 |
****************************************************************************
|
3555 |
Rule
|
3556 |
****************************************************************************
|
3557 |
-->71. The </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>class</span></b></tt><b><span
|
3558 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> declarations should
|
3559 |
have the following form: <o:p></o:p></span></b></p>
|
3560 |
</td>
|
3561 |
</tr>
|
3562 |
<tr style='mso-yfti-irow:1'>
|
3563 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3564 |
<p class=MsoNormal><span class=GramE><tt><span lang=EN-US style='font-size:
|
3565 |
10.0pt'>class</span></tt></span><tt><span lang=EN-US style='font-size:10.0pt'>
|
3566 |
SomeClass : public BaseClass</span></tt><span lang=EN-US style='font-size:
|
3567 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'> <tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
3568 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3569 |
public: </span></tt><br>
|
3570 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3571 |
... </span></tt><br>
|
3572 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3573 |
protected: </span></tt><br>
|
3574 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3575 |
... </span></tt><br>
|
3576 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3577 |
private: </span></tt><br>
|
3578 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3579 |
... </span></tt><br>
|
3580 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3581 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3582 |
</td>
|
3583 |
</tr>
|
3584 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3585 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3586 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3587 |
Arial'>This follows partly from the general block rule above. <o:p> Must follow the order of these access keyword, public comes first, and then protected and private </o:p></span></p>
|
3588 |
</td>
|
3589 |
</tr>
|
3590 |
</table>
|
3591 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3592 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3593 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3594 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3595 |
<tr style='mso-yfti-irow:0'>
|
3596 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3597 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3598 |
Arial'><!--
|
3599 |
****************************************************************************
|
3600 |
Rule
|
3601 |
****************************************************************************
|
3602 |
-->72. The function declarations should have the following form: <o:p></o:p></span></b></p>
|
3603 |
</td>
|
3604 |
</tr>
|
3605 |
<tr style='mso-yfti-irow:1'>
|
3606 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3607 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>void
|
3608 |
someMethod() </span></tt><span lang=EN-US style='font-size:10.0pt;
|
3609 |
font-family:fixed;mso-bidi-font-family:"Courier New"'> <tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
3610 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3611 |
...</span></tt><br>
|
3612 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3613 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3614 |
</td>
|
3615 |
</tr>
|
3616 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3617 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3618 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3619 |
Arial'>This follows from the general block rule above. <o:p></o:p></span></p>
|
3620 |
</td>
|
3621 |
</tr>
|
3622 |
</table>
|
3623 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3624 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3625 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3626 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3627 |
<tr style='mso-yfti-irow:0'>
|
3628 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3629 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3630 |
Arial'><!--
|
3631 |
****************************************************************************
|
3632 |
Rule
|
3633 |
****************************************************************************
|
3634 |
-->73. The </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>if-else</span></b></tt><b><span
|
3635 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> class of statements
|
3636 |
should have the following form: <o:p></o:p></span></b></p>
|
3637 |
</td>
|
3638 |
</tr>
|
3639 |
<tr style='mso-yfti-irow:1'>
|
3640 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3641 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>if
|
3642 |
(condition) {</span></tt><span lang=EN-US style='font-size:10.0pt;
|
3643 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3644 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3645 |
statements;</span></tt><br>
|
3646 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt><br>
|
3647 |
<br>
|
3648 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if
|
3649 |
(condition) {</span></tt><br>
|
3650 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3651 |
statements;</span></tt><br>
|
3652 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>else
|
3653 |
{</span></tt><br>
|
3654 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3655 |
statements;</span></tt><br>
|
3656 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt><br>
|
3657 |
<br>
|
3658 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>if
|
3659 |
(condition) {</span></tt><br>
|
3660 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3661 |
statements;</span></tt><br>
|
3662 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} else if
|
3663 |
(condition) {</span></tt><br>
|
3664 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3665 |
statements;</span></tt><br>
|
3666 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} else
|
3667 |
{</span></tt><br>
|
3668 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3669 |
statements;</span></tt><br>
|
3670 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3671 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3672 |
</td>
|
3673 |
</tr>
|
3674 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3675 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3676 |
<p class=MsoNormal><span
|
3677 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'><o:p></o:p></span></p>
|
3678 |
</td>
|
3679 |
</tr>
|
3680 |
</table>
|
3681 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3682 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3683 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3684 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3685 |
<tr style='mso-yfti-irow:0'>
|
3686 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3687 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3688 |
Arial'><!--
|
3689 |
****************************************************************************
|
3690 |
Rule
|
3691 |
****************************************************************************
|
3692 |
-->74. A </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>for</span></b></tt><b><span
|
3693 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3694 |
have the following form: <o:p></o:p></span></b></p>
|
3695 |
</td>
|
3696 |
</tr>
|
3697 |
<tr style='mso-yfti-irow:1'>
|
3698 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3699 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>for
|
3700 |
(initialization; condition; update) {</span></tt><span lang=EN-US
|
3701 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3702 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3703 |
statements;</span></tt><br>
|
3704 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3705 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3706 |
</td>
|
3707 |
</tr>
|
3708 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3709 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3710 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3711 |
Arial'>This follows from the general block rule above. <o:p></o:p></span></p>
|
3712 |
</td>
|
3713 |
</tr>
|
3714 |
</table>
|
3715 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3716 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3717 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3718 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3719 |
<tr style='mso-yfti-irow:0'>
|
3720 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3721 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3722 |
Arial'><!--
|
3723 |
****************************************************************************
|
3724 |
Rule
|
3725 |
****************************************************************************
|
3726 |
-->75. An empty </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>for</span></b></tt><b><span
|
3727 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3728 |
have the following form: <o:p></o:p></span></b></p>
|
3729 |
</td>
|
3730 |
</tr>
|
3731 |
<tr style='mso-yfti-irow:1'>
|
3732 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3733 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>for
|
3734 |
(initialization; condition; update)</span></tt><span lang=EN-US
|
3735 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3736 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3737 |
; </span></tt></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
3738 |
Arial'><o:p></o:p></span></p>
|
3739 |
</td>
|
3740 |
</tr>
|
3741 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3742 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3743 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3744 |
Arial'>This emphasize the fact that <span class=GramE>the for</span>
|
3745 |
statement is empty and it makes it obvious for the reader that this is
|
3746 |
intentional. Empty loops should be avoided however. <o:p></o:p></span></p>
|
3747 |
</td>
|
3748 |
</tr>
|
3749 |
</table>
|
3750 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3751 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3752 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3753 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3754 |
<tr style='mso-yfti-irow:0'>
|
3755 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3756 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3757 |
Arial'><!--
|
3758 |
****************************************************************************
|
3759 |
Rule
|
3760 |
****************************************************************************
|
3761 |
-->76. A </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>while</span></b></tt><b><span
|
3762 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3763 |
have the following form: <o:p></o:p></span></b></p>
|
3764 |
</td>
|
3765 |
</tr>
|
3766 |
<tr style='mso-yfti-irow:1'>
|
3767 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3768 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>while
|
3769 |
(condition) {</span></tt><span lang=EN-US style='font-size:10.0pt;
|
3770 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3771 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3772 |
statements;</span></tt><br>
|
3773 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3774 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3775 |
</td>
|
3776 |
</tr>
|
3777 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3778 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3779 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3780 |
Arial'>This follows from the general block rule above. <o:p></o:p></span></p>
|
3781 |
</td>
|
3782 |
</tr>
|
3783 |
</table>
|
3784 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3785 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3786 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3787 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3788 |
<tr style='mso-yfti-irow:0'>
|
3789 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3790 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3791 |
Arial'><!--
|
3792 |
****************************************************************************
|
3793 |
Rule
|
3794 |
****************************************************************************
|
3795 |
-->77. A </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>do-while</span></b></tt><b><span
|
3796 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3797 |
have the following form: <o:p></o:p></span></b></p>
|
3798 |
</td>
|
3799 |
</tr>
|
3800 |
<tr style='mso-yfti-irow:1'>
|
3801 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3802 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>do {</span></tt><span
|
3803 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3804 |
"Courier New"'><br>
|
3805 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3806 |
statements;</span></tt><br>
|
3807 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}
|
3808 |
while (condition);</span></tt></span><span lang=EN-US style='font-size:
|
3809 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3810 |
</td>
|
3811 |
</tr>
|
3812 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3813 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3814 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3815 |
Arial'>This follows from the general block rule above. <o:p></o:p></span></p>
|
3816 |
</td>
|
3817 |
</tr>
|
3818 |
</table>
|
3819 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3820 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3821 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3822 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3823 |
<tr style='mso-yfti-irow:0'>
|
3824 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3825 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3826 |
Arial'><!--
|
3827 |
****************************************************************************
|
3828 |
Rule
|
3829 |
****************************************************************************
|
3830 |
-->78. A </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>switch</span></b></tt><b><span
|
3831 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3832 |
have the following form: <o:p></o:p></span></b></p>
|
3833 |
</td>
|
3834 |
</tr>
|
3835 |
<tr style='mso-yfti-irow:1'>
|
3836 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3837 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>switch
|
3838 |
(condition) {</span></tt><span lang=EN-US style='font-size:10.0pt;
|
3839 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3840 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3841 |
case ABC : </span></tt><br>
|
3842 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3843 |
statements;</span></tt><br>
|
3844 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3845 |
break; </span></tt></span></p>
|
3846 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;
|
3847 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3848 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3849 |
default : </span></tt><br>
|
3850 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3851 |
statements;</span></tt><br>
|
3852 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3853 |
break;</span></tt><br>
|
3854 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3855 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p></td>
|
3856 |
</tr>
|
3857 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3858 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3859 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3860 |
Arial'>Note that each </span><tt><span lang=EN-US style='font-size:7.5pt'>case</span></tt><span
|
3861 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'> keyword is indented
|
3862 |
relative to the switch statement as a whole. This makes the entire switch
|
3863 |
statement stand out. Note also the extra space before <span class=GramE>the
|
3864 |
<i>:</i></span> character. The explicit <i>Fallthrough</i> comment should
|
3865 |
be included whenever there is a case statement without a </span><tt><span
|
3866 |
lang=EN-US style='font-size:7.5pt'>break</span></tt><span lang=EN-US
|
3867 |
style='font-size:7.5pt;font-family:Arial'> statement. Leaving the </span><tt><span
|
3868 |
lang=EN-US style='font-size:7.5pt'>break</span></tt><span lang=EN-US
|
3869 |
style='font-size:7.5pt;font-family:Arial'> out is a common error, and it
|
3870 |
must be made clear that it is intentional when it is not there. <o:p></o:p></span></p>
|
3871 |
</td>
|
3872 |
</tr>
|
3873 |
</table>
|
3874 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3875 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3876 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3877 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3878 |
<tr style='mso-yfti-irow:0'>
|
3879 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3880 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3881 |
Arial'><!--
|
3882 |
****************************************************************************
|
3883 |
Rule
|
3884 |
****************************************************************************
|
3885 |
-->79. A </span></b><tt><b><span lang=EN-US style='font-size:10.0pt'>try-catch</span></b></tt><b><span
|
3886 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'> statement should
|
3887 |
have the following form: <o:p></o:p></span></b></p>
|
3888 |
</td>
|
3889 |
</tr>
|
3890 |
<tr style='mso-yfti-irow:1'>
|
3891 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3892 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>try {</span></tt><span
|
3893 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3894 |
"Courier New"'><br>
|
3895 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3896 |
statements;</span></tt><br>
|
3897 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} catch
|
3898 |
(Exception &exception) {</span></tt><br>
|
3899 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3900 |
statements;</span></tt><br>
|
3901 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span
|
3902 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3903 |
</td>
|
3904 |
</tr>
|
3905 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3906 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3907 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3908 |
Arial'>This follows partly from the general block rule above. The <span
|
3909 |
class=GramE>discussion about closing brackets for <tt><span
|
3910 |
style='mso-ansi-font-size:7.5pt;mso-bidi-font-size:7.5pt'>if-else
|
3911 |
statements apply</span></tt></span></span><tt><span lang=EN-US
|
3912 |
style='font-size:7.5pt'> to the try-catch statments. </span></tt><span
|
3913 |
lang=EN-US style='font-size:7.5pt;font-family:Arial'><o:p></o:p></span></p>
|
3914 |
</td>
|
3915 |
</tr>
|
3916 |
</table>
|
3917 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3918 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3919 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3920 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3921 |
<tr style='mso-yfti-irow:0'>
|
3922 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3923 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3924 |
Arial'><!--
|
3925 |
****************************************************************************
|
3926 |
Rule
|
3927 |
****************************************************************************
|
3928 |
-->80. Single statement </span></b><tt><b><span lang=EN-US style='font-size:
|
3929 |
10.0pt'>if-else</span></b></tt><b><span lang=EN-US style='font-size:10.0pt;
|
3930 |
font-family:Arial'>, </span></b><tt><b><span lang=EN-US style='font-size:
|
3931 |
10.0pt'>for</span></b></tt><b><span lang=EN-US style='font-size:10.0pt;
|
3932 |
font-family:Arial'> or </span></b><tt><b><span lang=EN-US style='font-size:
|
3933 |
10.0pt'>while</span></b></tt><b><span lang=EN-US style='font-size:10.0pt;
|
3934 |
font-family:Arial'> statements can be written without brackets. <o:p></o:p></span></b></p>
|
3935 |
</td>
|
3936 |
</tr>
|
3937 |
<tr style='mso-yfti-irow:1'>
|
3938 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3939 |
<p class=MsoNormal style='margin-bottom:12.0pt'><tt><span lang=EN-US
|
3940 |
style='font-size:10.0pt'>if (condition) </span></tt><span lang=EN-US
|
3941 |
style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
3942 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3943 |
statement;</span></tt><br>
|
3944 |
<br>
|
3945 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while
|
3946 |
(condition) </span></tt><br>
|
3947 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3948 |
statement;</span></tt><br>
|
3949 |
<br>
|
3950 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for (initialization;
|
3951 |
condition; update) </span></tt><br>
|
3952 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3953 |
statement;</span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
3954 |
font-family:Arial'><o:p></o:p></span></p>
|
3955 |
</td>
|
3956 |
</tr>
|
3957 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3958 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3959 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3960 |
Arial'>It is a common recommendation (Sun Java recommendation included)
|
3961 |
that brackets should always be used in all these cases. However, brackets
|
3962 |
are in general a language construct that groups several statements.
|
3963 |
Brackets are per definition superfluous on a single statement. <o:p></o:p></span></p>
|
3964 |
</td>
|
3965 |
</tr>
|
3966 |
</table>
|
3967 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
3968 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
3969 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
3970 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
3971 |
<tr style='mso-yfti-irow:0'>
|
3972 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
3973 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
3974 |
Arial'><!--
|
3975 |
****************************************************************************
|
3976 |
Rule
|
3977 |
****************************************************************************
|
3978 |
-->81. The function return type can be put in the left column immediately above
|
3979 |
the function name. <o:p></o:p></span></b></p>
|
3980 |
</td>
|
3981 |
</tr>
|
3982 |
<tr style='mso-yfti-irow:1'>
|
3983 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3984 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>void</span></tt><span
|
3985 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
3986 |
"Courier New"'> <tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:
|
3987 |
10.0pt'>MyClass::myMethod ()</span> <span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>{</span></tt><br>
|
3988 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
3989 |
:</span></tt><br>
|
3990 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span><span
|
3991 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
3992 |
</td>
|
3993 |
</tr>
|
3994 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
3995 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
3996 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
3997 |
Arial'>This makes it easier to spot function names within a file since one
|
3998 |
can assume that they all start in the first column. <o:p></o:p></span></p>
|
3999 |
</td>
|
4000 |
</tr>
|
4001 |
</table>
|
4002 |
<h3><a name="White_Space"></a><span lang=EN-US>6.2 White Space<o:p></o:p></span></h3>
|
4003 |
<!--
|
4004 |
****************************************************************************
|
4005 |
Rule
|
4006 |
****************************************************************************
|
4007 |
-->
|
4008 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4009 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4010 |
<tr style='mso-yfti-irow:0'>
|
4011 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4012 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4013 |
Arial'>82<span class=GramE>.</span><br>
|
4014 |
- Conventional operators should be surrounded by a space character. <br>
|
4015 |
- C++ reserved words should be followed by a white space. <br>
|
4016 |
- Commas should be followed by a white space. <br>
|
4017 |
- Colons should be surrounded by white space. <br>
|
4018 |
- Semicolons in for statments should be followed by a space character. <o:p></o:p></span></b></p>
|
4019 |
</td>
|
4020 |
</tr>
|
4021 |
<tr style='mso-yfti-irow:1'>
|
4022 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4023 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>a = (b +
|
4024 |
c) * d;</span></tt><span lang=EN-US style='font-size:
|
4025 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
4026 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while
|
4027 |
(true) {</span></tt><br>
|
4028 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>doSomething
|
4029 |
(a, b, c, d);</span></tt><br>
|
4030 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>case
|
4031 |
100 :</span></tt><br>
|
4032 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for
|
4033 |
(i = 0; i < 10; i++) {</span></tt></span><span
|
4034 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
4035 |
</td>
|
4036 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><span class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>a=(b+c)*d</span></tt><span lang=EN-US style='font-size:
|
4037 |
10.0pt;font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
4038 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>while(true) ...</span></tt><br>
|
4039 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>doSomething (a,b,c,d);</span></tt><br>
|
4040 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>case 100:</span></tt><br>
|
4041 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>for (i=0;i<10;i++){ </span></tt></span><span
|
4042 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></span></td>
|
4043 |
</tr>
|
4044 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4045 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
4046 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4047 |
Arial'>Makes the individual components of the statements stand out.
|
4048 |
Enhances readability. It is difficult to give a complete list of the
|
4049 |
suggested use of whitespace in C++ code. The examples above however should
|
4050 |
give a general idea of the intentions. <o:p></o:p></span></p>
|
4051 |
</td>
|
4052 |
</tr>
|
4053 |
</table>
|
4054 |
<!--
|
4055 |
****************************************************************************
|
4056 |
Rule
|
4057 |
****************************************************************************
|
4058 |
-->
|
4059 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4060 |
style='display:none;mso-hide:all'><o:p> </o:p></span><span lang=EN-US
|
4061 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4062 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4063 |
style='width:100.0%; mso-cellspacing:1.5pt; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; margin-bottom: .0001pt;'>
|
4064 |
<tr style='mso-yfti-irow:0'>
|
4065 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4066 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4067 |
Arial'><!--
|
4068 |
****************************************************************************
|
4069 |
Rule
|
4070 |
****************************************************************************
|
4071 |
-->83. Logical units within a block should be separated by one blank line. <o:p></o:p></span></b></p>
|
4072 |
</td>
|
4073 |
</tr>
|
4074 |
<tr style='mso-yfti-irow:1'>
|
4075 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4076 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
4077 |
Arial'><o:p> </o:p></span></p>
|
4078 |
</td>
|
4079 |
</tr>
|
4080 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4081 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4082 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4083 |
Arial'>Enhance readability by introducing white space between logical units
|
4084 |
of a block. <o:p></o:p></span></p>
|
4085 |
</td>
|
4086 |
</tr>
|
4087 |
</table>
|
4088 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4089 |
style='display:none;mso-hide:all'><o:p> </o:p></span><span lang=EN-US
|
4090 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4091 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4092 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4093 |
<tr style='mso-yfti-irow:0'>
|
4094 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4095 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4096 |
Arial'><!--
|
4097 |
****************************************************************************
|
4098 |
Rule
|
4099 |
****************************************************************************
|
4100 |
-->84. Variables in declarations should be left aligned. <o:p></o:p></span></b></p>
|
4101 |
</td>
|
4102 |
</tr>
|
4103 |
<tr style='mso-yfti-irow:1'>
|
4104 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4105 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>AsciiFile
|
4106 |
*file;</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
4107 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
4108 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>int
|
4109 |
nPoints;</span></tt><br>
|
4110 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>float
|
4111 |
x, y; </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4112 |
font-family:Arial'><o:p></o:p></span></p>
|
4113 |
</td>
|
4114 |
</tr>
|
4115 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4116 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4117 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4118 |
Arial'>Enhance readability. The variables are easier to spot from the types
|
4119 |
by alignment. <o:p></o:p></span></p>
|
4120 |
</td>
|
4121 |
</tr>
|
4122 |
</table>
|
4123 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4124 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4125 |
<h3><a name=Comments_and_Documentation id="Comments_and_Documentation" and Documentation></a><span lang=EN-US>7 Comments and Documentation</span></h3>
|
4126 |
<h3><span lang=EN-US><span lang=EN-US><a name=Comment id="Comment"></a></span>7.1 Comment</span></h3>
|
4127 |
<!--
|
4128 |
****************************************************************************
|
4129 |
Rule
|
4130 |
****************************************************************************
|
4131 |
-->
|
4132 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4133 |
style='display:none;mso-hide:all'><o:p> </o:p></span><span lang=EN-US
|
4134 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4135 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4136 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4137 |
<tr style='mso-yfti-irow:0'>
|
4138 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4139 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4140 |
Arial'>85. Use <i>//</i> for all comments, including multi-line comments. <o:p></o:p></span></b></p>
|
4141 |
</td>
|
4142 |
</tr>
|
4143 |
<tr style='mso-yfti-irow:1'>
|
4144 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4145 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>// Comment
|
4146 |
spanning</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:
|
4147 |
fixed;mso-bidi-font-family:"Courier New"'><br>
|
4148 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>//
|
4149 |
more than one line. </span></tt></span><span lang=EN-US style='font-size:
|
4150 |
10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
4151 |
</td>
|
4152 |
</tr>
|
4153 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4154 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4155 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4156 |
Arial'>Since multilevel C-commenting is not supported, using // comments
|
4157 |
ensure that it is always possible to comment out entire sections of a file
|
4158 |
using /* */ for debugging purposes etc. <o:p></o:p></span></p>
|
4159 |
<p><span lang=EN-US>There should be a space between the "//" and
|
4160 |
the actual comment, and comments should always start with an upper case
|
4161 |
letter and end with a period. </span></p>
|
4162 |
</td>
|
4163 |
</tr>
|
4164 |
</table>
|
4165 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4166 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4167 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4168 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4169 |
<tr style='mso-yfti-irow:0'>
|
4170 |
<td colspan="2" style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4171 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4172 |
Arial'><!--
|
4173 |
****************************************************************************
|
4174 |
Rule
|
4175 |
****************************************************************************
|
4176 |
-->
|
4177 |
86. Comments should be included relative to their position in the code. [1] <o:p></o:p></span></b></p>
|
4178 |
</td>
|
4179 |
</tr>
|
4180 |
<tr style='mso-yfti-irow:1'>
|
4181 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4182 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>while
|
4183 |
(true) {</span></tt><span lang=EN-US style='font-size:10.0pt;
|
4184 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
4185 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
4186 |
<span lang=EN-US style='font-size:10.0pt;
|
4187 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4188 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span>// Do something</span></tt><br>
|
4189 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>
|
4190 |
<span lang=EN-US style='font-size:10.0pt;
|
4191 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4192 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span>something(); </span></tt><br>
|
4193 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}</span></tt></span><span lang=EN-US style='font-size:10.0pt;font-family:
|
4194 |
Arial'><o:p></o:p></span></p>
|
4195 |
</td>
|
4196 |
<td bgcolor="#FDB5A6" style='padding:.75pt .75pt .75pt .75pt'><p class="MsoNormal"><tt><span lang=EN-US style='font-size:10.0pt'>while (true) {</span></tt><span lang=EN-US style='font-size:10.0pt;
|
4197 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><br>
|
4198 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> // Do something</span></tt><br>
|
4199 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> <span lang=EN-US style='font-size:10.0pt;
|
4200 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4201 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4202 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span><span lang=EN-US style='font-size:10.0pt;
|
4203 |
font-family:fixed;mso-bidi-font-family:"Courier New"'><tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> </span></tt></span>something();</span></tt><br>
|
4204 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>} </span></tt></span></p>
|
4205 |
<span class="MsoNormal"><span lang=EN-US style='font-size:10.0pt;font-family:
|
4206 |
Arial'><o:p></o:p></span></span></td>
|
4207 |
</tr>
|
4208 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4209 |
<td colspan="2" style='padding:.75pt .75pt .75pt .75pt'>
|
4210 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4211 |
Arial'>This is to avoid that the comments break the logical structure of
|
4212 |
the program. <o:p></o:p></span></p>
|
4213 |
</td>
|
4214 |
</tr>
|
4215 |
</table>
|
4216 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4217 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4218 |
<h3><span lang=EN-US><!--
|
4219 |
****************************************************************************
|
4220 |
Rule
|
4221 |
****************************************************************************
|
4222 |
-->
|
4223 |
<span lang=EN-US><a name=Documentation></a></span>7.2 Documentation</span></h3>
|
4224 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4225 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4226 |
<tr style='mso-yfti-irow:0'>
|
4227 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4228 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4229 |
Arial'>87. Documentation style should follow Doxygen conventions<o:p></o:p></span></b></p>
|
4230 |
</td>
|
4231 |
</tr>
|
4232 |
<tr style='mso-yfti-irow:1'>
|
4233 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4234 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
4235 |
Arial'><o:p> </o:p></span></p>
|
4236 |
</td>
|
4237 |
</tr>
|
4238 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4239 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4240 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4241 |
Arial'>Regarding standardized class and method documentation the Java
|
4242 |
development community is far more mature than the C++. This is of course
|
4243 |
becuase Java includes a tool for extracting such comments and produce high
|
4244 |
quality hypertext documentation from it. <o:p></o:p></span></p>
|
4245 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4246 |
Arial'><o:p> </o:p></span></p>
|
4247 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
4248 |
Arial'>There have never been a common convention for writing this kind of
|
4249 |
documentation in C++, so when choosing between inventing your own
|
4250 |
convention, and using an existing one, the latter option seem natural. As
|
4251 |
one of the most popular documentation tools for C++,</span><span
|
4252 |
lang=EN-US> <a href="http://www.stack.nl/~dimitri/doxygen/index.html"><span
|
4253 |
style='font-size:10.0pt;font-family:Arial'>Doxygen</span></a> </span><span
|
4254 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'>become our primary
|
4255 |
choice. </span><span lang=EN-US style='font-size:7.5pt;font-family:Arial'><o:p></o:p></span></p>
|
4256 |
</td>
|
4257 |
</tr>
|
4258 |
</table>
|
4259 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4260 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4261 |
<!--
|
4262 |
****************************************************************************
|
4263 |
Rule
|
4264 |
****************************************************************************
|
4265 |
-->
|
4266 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4267 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4268 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4269 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4270 |
<tr style='mso-yfti-irow:0'>
|
4271 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4272 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4273 |
Arial'>88. </span></b><span lang=EN-US style='color:black; font-weight: bold; font-family: Arial, Helvetica, sans-serif; font-size: 10pt;'>Documentation
|
4274 |
block style</span><span class="style12"><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></span><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4275 |
Arial'><o:p></o:p></span></b></p>
|
4276 |
</td>
|
4277 |
</tr>
|
4278 |
<tr style='mso-yfti-irow:1'>
|
4279 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4280 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>/**<o:p></o:p></span></tt></p>
|
4281 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4282 |
style='mso-spacerun:yes'> </span>*<span style='mso-spacerun:yes'> </span>…
|
4283 |
text …<o:p></o:p></span></tt></p>
|
4284 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4285 |
style='mso-spacerun:yes'> </span>*/</span></tt><span lang=EN-US
|
4286 |
style='mso-bidi-font-family:Arial'><o:p></o:p></span></p>
|
4287 |
</td>
|
4288 |
</tr>
|
4289 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4290 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4291 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4292 |
Arial'>In Doxygen, there are several valid way to mark a documentation
|
4293 |
block, we prefer the java style<span style='mso-spacerun:yes'> </span><o:p></o:p></span></p>
|
4294 |
<p><span lang=EN-US><o:p> </o:p></span></p>
|
4295 |
</td>
|
4296 |
</tr>
|
4297 |
</table>
|
4298 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4299 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4300 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4301 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4302 |
<tr style='mso-yfti-irow:0'>
|
4303 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4304 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4305 |
Arial'><!--
|
4306 |
****************************************************************************
|
4307 |
Rule
|
4308 |
****************************************************************************
|
4309 |
-->
|
4310 |
89. <b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4311 |
Arial'>@ tag convention </span></b><o:p> should be used </o:p></span></b></p> </td>
|
4312 |
</tr>
|
4313 |
<tr style='mso-yfti-irow:1'>
|
4314 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4315 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>@author<o:p></o:p></span></tt></p>
|
4316 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>\authour</span></tt></p>
|
4317 |
</td>
|
4318 |
</tr>
|
4319 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4320 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4321 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4322 |
Arial'>Doxygen support two kinds of tag conventions which begin with
|
4323 |
“\” or “@”. Both of them are equivalent, however,
|
4324 |
we prefer the java style <o:p></o:p></span></p>
|
4325 |
<p class=MsoNormal><span lang=EN-US style='font-size:7.5pt;font-family:
|
4326 |
Arial'><o:p></o:p></span></p>
|
4327 |
<p class=MsoNormal><o:p><span class="MsoNormal style7">One obviuos ex</span>ception is using Latex to represent formula </o:p></p></td>
|
4328 |
</tr>
|
4329 |
</table>
|
4330 |
<p style='margin:0cm'><span lang=EN-US
|
4331 |
style='display:none;mso-hide:all'><o:p></o:p></span><span lang=EN-US style='font-size:10.0pt;font-family:Arial;
|
4332 |
display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4333 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4334 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4335 |
<tr style='mso-yfti-irow:0'>
|
4336 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4337 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4338 |
Arial'>
|
4339 |
<!--
|
4340 |
****************************************************************************
|
4341 |
Rule
|
4342 |
****************************************************************************
|
4343 |
-->
|
4344 |
90. <b>File Documentation </b><o:p></o:p></span></b></p></td>
|
4345 |
</tr>
|
4346 |
<tr style='mso-yfti-irow:1'>
|
4347 |
<td style='padding:.75pt .75pt .75pt .75pt'><p class=MsoNormal style4><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt></p>
|
4348 |
<p class=MsoNormal style4><tt><span lang=EN-US style='font-size:10.0pt'><o:p>/*<br>
|
4349 |
<tt><span lang=EN-US
|
4350 |
style='font-size:10.0pt'> </span></tt>* Copyright (C) 2000-2009 The Open Molecular Dynamics Engine (OpenMD) project<br>
|
4351 |
* <br>
|
4352 |
* Contact: gezelter@openscience.org<br>
|
4353 |
* <br>
|
4354 |
* This program is free software; you can redistribute it and/or<br>
|
4355 |
* modify it under the terms of the GNU Lesser General Public License<br>
|
4356 |
* as published by the Free Software Foundation; either version 2.1<br>
|
4357 |
* of the License, or (at your option) any later version.<br>
|
4358 |
* All we ask is that proper credit is given for our work, which includes<br>
|
4359 |
* - but is not limited to - adding the above copyright notice to the beginning<br>
|
4360 |
* of your source code files, and to any copyright notice that you may distribute<br>
|
4361 |
* with programs based on this work.<br>
|
4362 |
* <br>
|
4363 |
* This program is distributed in the hope that it will be useful,<br>
|
4364 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
|
4365 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
|
4366 |
* GNU Lesser General Public License for more details.<br>
|
4367 |
* <br>
|
4368 |
* You should have received a copy of the GNU Lesser General Public License<br>
|
4369 |
* along with this program; if not, write to the Free Software<br>
|
4370 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br>
|
4371 |
*<br>
|
4372 |
*/</o:p></span></tt></p>
|
4373 |
<p> /**<br>
|
4374 |
* @file StringTokenizer.hpp<br>
|
4375 |
* @author tlin<br>
|
4376 |
* @date 09/20/2004<br>
|
4377 |
* @time 11:30am<br>
|
4378 |
* @version 1.0<br>
|
4379 |
*/<tt><span lang=EN-US style='font-size:10.0pt'><o:p><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt></o:p></span></tt></p> </td>
|
4380 |
</tr>
|
4381 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4382 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4383 |
<p class=MsoNormal><o:p></o:p></p>
|
4384 |
</td>
|
4385 |
</tr>
|
4386 |
</table>
|
4387 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4388 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4389 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4390 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4391 |
<tr style='mso-yfti-irow:0'>
|
4392 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4393 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4394 |
Arial'>
|
4395 |
91. Variable (include class member variable, struct member variable, union member variable and enum member variable) should be documented right after its declaration <o:p></o:p></span></b></p></td>
|
4396 |
</tr>
|
4397 |
<tr style='mso-yfti-irow:1'>
|
4398 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4399 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>vector<int>::iterator i;<span
|
4400 |
style='mso-spacerun:yes'> </span>/**< iterator */ <o:p></o:p></span></tt></p>
|
4401 |
<p class=MsoNormal><span
|
4402 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p></td>
|
4403 |
</tr>
|
4404 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4405 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4406 |
<p class=MsoNormal>Although Doxygen support several kinds of variable documentation, we prefer /**< ... */ </p></td>
|
4407 |
</tr>
|
4408 |
</table>
|
4409 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4410 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4411 |
<p style='margin:0cm;margin-bottom:.0001pt'>
|
4412 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4413 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4414 |
<tr style='mso-yfti-irow:0'>
|
4415 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4416 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4417 |
Arial'>
|
4418 |
92. Class, Struct, Union, typedef and function (include class member function) should be documented right before their declaration <o:p></o:p></span></b></p></td>
|
4419 |
</tr>
|
4420 |
<tr style='mso-yfti-irow:1'>
|
4421 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4422 |
<p class=MsoNormal><span
|
4423 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p>
|
4424 |
</td>
|
4425 |
</tr>
|
4426 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4427 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4428 |
<p class=MsoNormal> </p></td>
|
4429 |
</tr>
|
4430 |
</table>
|
4431 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4432 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4433 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4434 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4435 |
<tr style='mso-yfti-irow:0'>
|
4436 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4437 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4438 |
Arial'>
|
4439 |
<!--
|
4440 |
****************************************************************************
|
4441 |
Rule
|
4442 |
****************************************************************************
|
4443 |
-->
|
4444 |
93. <b>Class Documentation</b><o:p></o:p></span></b></p></td>
|
4445 |
</tr>
|
4446 |
<tr style='mso-yfti-irow:1'>
|
4447 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4448 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt><tt> </tt></p>
|
4449 |
<p class="style4"> /**<br>
|
4450 |
* @class StringTokenizer StringTokenizer.hpp "util/StringTokenizer.hpp"<br>
|
4451 |
*<br>
|
4452 |
* @brief The string tokenizer class allows an application to break a string into tokens<br>
|
4453 |
*<br>
|
4454 |
* The set of delimiters (the characters that separate tokens) may be specified either <br>
|
4455 |
* at creation time or on a per-token basis. <br>
|
4456 |
* An instance of StringTokenizer behaves in one of two ways, depending on whether it was <br>
|
4457 |
* created with the returnTokens flag having the value true or false.<br>
|
4458 |
*/<br>
|
4459 |
class StringTokenizer{<br>
|
4460 |
<br>
|
4461 |
public:<br>
|
4462 |
<br>
|
4463 |
/**<br>
|
4464 |
* Constructs a string tokenizer for the specified string. The characters in the delim argument<br>
|
4465 |
* are the delimiters for separating tokens. characters are skipped and only serve as <br>
|
4466 |
* separators between tokens.<br>
|
4467 |
* @param str a string to be parsed.<br>
|
4468 |
* @param delim the delimiters, default value is "\t\n\r".<br>
|
4469 |
*/<br>
|
4470 |
StringTokenizer(const std::string &str, const std::string &delim = "\t\n\r");</p>
|
4471 |
<p class="style4"> /**<br>
|
4472 |
* Constructs a string tokenizer for the specified string. The characters in the delim argument<br>
|
4473 |
* are the delimiters for separating tokens. <br>
|
4474 |
* If the returnTokens flag is true, then the delimiter characters are also returned as tokens. <br>
|
4475 |
* Each delimiter is returned as a string of length one. If the flag is false, the delimiter <br>
|
4476 |
* characters are skipped and only serve as separators between tokens.<br>
|
4477 |
* @param str a string to be parsed. <br>
|
4478 |
* @param delim the delimiters. <br>
|
4479 |
* @param returnTokens flag indicating whether to return the delimiters as tokens.<br>
|
4480 |
*/<br>
|
4481 |
StringTokenizer(const std::string& str, const std::string& delim, bool returnTokens);</p>
|
4482 |
<p class="style4"> /**<br>
|
4483 |
* Calculates the number of times that this tokenizer's nextToken method can be called <br>
|
4484 |
* before it generates an exception.<br>
|
4485 |
*<br>
|
4486 |
* @return the number of tokens remaining in the string using the current delimiter set.<br>
|
4487 |
*/<br>
|
4488 |
int countTokens();</p>
|
4489 |
<p class="style4"> /**<br>
|
4490 |
* Tests if there are more tokens available from this tokenizer's string.<br>
|
4491 |
*<br>
|
4492 |
* @return true if there are more tokens available from this tokenizer's string, false otherwise<br>
|
4493 |
*/<br>
|
4494 |
bool hasMoreTokens();</p>
|
4495 |
<p class="style4"> /**<br>
|
4496 |
* Returns the next token from this string tokenizer.<br>
|
4497 |
*<br>
|
4498 |
* @return the next token from this string tokenizer.<br>
|
4499 |
*<br>
|
4500 |
* @exception NoSuchElementException if there are no more tokens in this tokenizer's string<br>
|
4501 |
*/<br>
|
4502 |
std::string nextToken();</p>
|
4503 |
<p class="style4"> /**<br>
|
4504 |
* Returns the next token in this string tokenizer's string. The new delimiter set remains the<br>
|
4505 |
* default after this call.<br>
|
4506 |
*<br>
|
4507 |
* @param newDelim the new delimiters.<br>
|
4508 |
*<br>
|
4509 |
* @return the next token, after switching to the new delimiter set.<br>
|
4510 |
*<br>
|
4511 |
* @exception NoSuchElementException if there are no more tokens in this tokenizer's string.<br>
|
4512 |
*<br>
|
4513 |
*/<br>
|
4514 |
std::string nextToken(const std::string& newDelim); </p>
|
4515 |
<p class="style4"> /**<br>
|
4516 |
* Returns the current delimiter set of this string tokenizer<br>
|
4517 |
*<br>
|
4518 |
* @return the current delimiter set<br>
|
4519 |
*/<br>
|
4520 |
std::string getDelimiter();</p>
|
4521 |
<p class="style4"> private:<br>
|
4522 |
<br>
|
4523 |
/**<br>
|
4524 |
* Test if character is in current delimiter set.<br>
|
4525 |
*<br>
|
4526 |
* @param c character to be tested<br>
|
4527 |
*<br>
|
4528 |
* @return true if character is in current delimiter set, flase otherwise.<br>
|
4529 |
*/<br>
|
4530 |
bool isDelimiter(char c);<br>
|
4531 |
<br>
|
4532 |
std::string delim_; /**< current delimiter set of this string tokenizer */</p>
|
4533 |
<p class="style4"> bool returnTokens_; /**< flag indicating whether to return the delimiters as tokens */<br>
|
4534 |
};</p>
|
4535 |
</td>
|
4536 |
</tr>
|
4537 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4538 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4539 |
<p class=MsoNormal><o:p></o:p></p>
|
4540 |
</td>
|
4541 |
</tr>
|
4542 |
</table>
|
4543 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4544 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4545 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4546 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4547 |
<tr style='mso-yfti-irow:0'>
|
4548 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4549 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
|
4550 |
Arial'>
|
4551 |
94. struct documentation <o:p></o:p></span></b></p></td>
|
4552 |
</tr>
|
4553 |
<tr style='mso-yfti-irow:1'>
|
4554 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4555 |
<p class=MsoNormal> </p>
|
4556 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>/**</span></tt></p>
|
4557 |
<p class=MsoNormal><tt><span class="style10"> * @struct Employee </span></tt></p>
|
4558 |
<p class=MsoNormal><tt><span class="style10"> * @brief Employee struct contains some properties of an employee object </span></tt></p>
|
4559 |
<p class=MsoNormal><tt><span class="style10"> * detail description </span></tt></p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> */</span></tt> </p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>struct Employee {</span></tt></p>
|
4560 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> <tt><span lang=EN-US style='font-size:10.0pt'><span
|
4561 |
style='mso-spacerun:yes'> </span></span></tt>int id; /**< employee indentification number */ <o:p></o:p></span></tt></p>
|
4562 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4563 |
style='mso-spacerun:yes'> </span>string firstName;<span
|
4564 |
style='mso-spacerun:yes'> </span>/**< first name */ <o:p></o:p></span></tt></p>
|
4565 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4566 |
style='mso-spacerun:yes'> </span></span></tt>string lastName;<span
|
4567 |
style='mso-spacerun:yes'> </span> /**< last name */ <o:p></o:p></span></tt></p>
|
4568 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4569 |
style='mso-spacerun:yes'> </span></span></tt>string title;<o:p></o:p></span></tt><tt><span lang=EN-US style='font-size:10.0pt'> <tt><span lang=EN-US style='font-size:10.0pt'> </span></tt>/**< job title */ </span></tt></p>
|
4570 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>}<o:p>;</o:p></span></tt><span
|
4571 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p>
|
4572 |
</td>
|
4573 |
</tr>
|
4574 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4575 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4576 |
<p class=MsoNormal> </p></td>
|
4577 |
</tr>
|
4578 |
</table>
|
4579 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4580 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4581 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4582 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4583 |
<tr style='mso-yfti-irow:0'>
|
4584 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4585 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4586 |
95. union documentation <o:p></o:p></span></b></p></td>
|
4587 |
</tr>
|
4588 |
<tr style='mso-yfti-irow:1'>
|
4589 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4590 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>/**</span></tt></p>
|
4591 |
<p class=MsoNormal><tt><span class="style10"> * @union <tt><span lang=EN-US style='font-size:10.0pt'>Parameter</span></tt></span></tt></p>
|
4592 |
<p class=MsoNormal><tt><span class="style10"> * @brief ...</span></tt></p>
|
4593 |
<p class=MsoNormal><tt><span class="style10"> * detail description </span></tt></p>
|
4594 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> */</span></tt> </p>
|
4595 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>union Parameter {</span></tt></p>
|
4596 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> <tt><span lang=EN-US style='font-size:10.0pt'><span
|
4597 |
style='mso-spacerun:yes'> </span></span></tt>int intVar; /**< integer parameter */ <o:p></o:p></span></tt></p>
|
4598 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4599 |
style='mso-spacerun:yes'> </span>float floatVar;<span
|
4600 |
style='mso-spacerun:yes'> </span>/**< float parameter */ <o:p></o:p></span></tt></p>
|
4601 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><tt><span lang=EN-US style='font-size:10.0pt'><span
|
4602 |
style='mso-spacerun:yes'> </span></span></tt>string strVar;<span
|
4603 |
style='mso-spacerun:yes'> </span> /**< string paramter */ <o:p></o:p></span></tt></p>
|
4604 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>}<o:p>;</o:p></span></tt><span
|
4605 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p>
|
4606 |
<p class=MsoNormal><span
|
4607 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p></td>
|
4608 |
</tr>
|
4609 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4610 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4611 |
<p class=MsoNormal> </p></td>
|
4612 |
</tr>
|
4613 |
</table>
|
4614 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4615 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4616 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4617 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4618 |
<tr style='mso-yfti-irow:0'>
|
4619 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4620 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4621 |
96. enum documentation <o:p></o:p></span></b></p></td>
|
4622 |
</tr>
|
4623 |
<tr style='mso-yfti-irow:1'>
|
4624 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4625 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p>/**</span></tt></p>
|
4626 |
<p class=MsoNormal><tt><span class="style10"> * @enum Color</span></tt></p>
|
4627 |
<p class=MsoNormal><tt><span class="style10"> * @brief ...</span></tt></p>
|
4628 |
<p class=MsoNormal><tt><span class="style10"> * detail description </span></tt></p>
|
4629 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> */</span></tt> </p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>enum Color {</span></tt><span lang=EN-US style='font-size:10.0pt;font-family:fixed;
|
4630 |
mso-bidi-font-family:"Courier New"'><br>
|
4631 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> COLOR_RED,</span></tt> /**< red color */ <br>
|
4632 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> COLOR_GREEN,</span></tt> /**< green color */ <br>
|
4633 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'> COLOR_BLUE</span></tt> <span lang=EN-US style='font-size:10.0pt;font-family:fixed;
|
4634 |
mso-bidi-font-family:"Courier New"'> </span>/**< blue color */ <br>
|
4635 |
<tt><span style='mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt'>}; </span></tt></span><span
|
4636 |
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span><span
|
4637 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p> </td>
|
4638 |
</tr>
|
4639 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4640 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4641 |
<p class=MsoNormal> </p></td>
|
4642 |
</tr>
|
4643 |
</table>
|
4644 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4645 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4646 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4647 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4648 |
<tr style='mso-yfti-irow:0'>
|
4649 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4650 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4651 |
97. typedef documentation <o:p></o:p></span></b></p></td>
|
4652 |
</tr>
|
4653 |
<tr style='mso-yfti-irow:1'>
|
4654 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4655 |
<p class=MsoNormal><span
|
4656 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span><tt><span lang=EN-US style='font-size:10.0pt'>/**</span></tt></p>
|
4657 |
<p class=MsoNormal><tt><span class="style10"> * @typedef IntVector </span></tt></p>
|
4658 |
<p class=MsoNormal><tt><span class="style10"> * @brief ...</span></tt></p>
|
4659 |
<p class=MsoNormal><tt><span class="style10"> * detail description </span></tt></p>
|
4660 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'> */</span></tt> </p>
|
4661 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'>typedef std::vector<int> IntVector;</span></tt><span
|
4662 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p> </td>
|
4663 |
</tr>
|
4664 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4665 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4666 |
<p class=MsoNormal> </p></td>
|
4667 |
</tr>
|
4668 |
</table>
|
4669 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4670 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4671 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4672 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4673 |
<tr style='mso-yfti-irow:0'>
|
4674 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4675 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4676 |
98. function documentation <o:p></o:p></span></b></p></td>
|
4677 |
</tr>
|
4678 |
<tr style='mso-yfti-irow:1'>
|
4679 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4680 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt><tt><span lang=EN-US style='font-size:10.0pt'><o:p>/**</o:p></span></tt></p>
|
4681 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> * @fn int open(const char *pathname,int flags)<br/>
|
4682 |
* @brief opens a file descriptor. <br/>
|
4683 |
* @param pathname the name of the descriptor. <br/>
|
4684 |
* @param flags opening flags.</o:p></span></tt></p>
|
4685 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> * @return <tt><span lang=EN-US style='font-size:10.0pt'>descriptor</span></tt> of the file, return -1 if error<br/>
|
4686 |
*/ </o:p></span></tt></p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p><tt><span lang=EN-US style='font-size:10.0pt'> int open(const char *pathname,int flags)</span></tt></o:p>;</span></tt><span
|
4687 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p>
|
4688 |
</td>
|
4689 |
</tr>
|
4690 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4691 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4692 |
<p class=MsoNormal> </p></td>
|
4693 |
</tr>
|
4694 |
</table>
|
4695 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4696 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4697 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4698 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4699 |
<tr style='mso-yfti-irow:0'>
|
4700 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4701 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4702 |
99. template function documentation <o:p></o:p></span></b></p></td>
|
4703 |
</tr>
|
4704 |
<tr style='mso-yfti-irow:1'>
|
4705 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4706 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt><tt><span lang=EN-US style='font-size:10.0pt'><o:p>/**</o:p></span></tt></p>
|
4707 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> * @fn <span lang=EN-US style='font-size:10.0pt;font-family:
|
4708 |
Arial'><span
|
4709 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
4710 |
"Courier New"'><span lang=EN-US style='font-size:10.0pt;font-family:
|
4711 |
Arial'><span
|
4712 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
4713 |
"Courier New"'>template <typename T></span></span> inline const T& max (const T &a, const T &b)</span></span><br/>
|
4714 |
* @brief
|
4715 |
|
4716 |
|
4717 |
Compares two objects and returns the larger of the two
|
4718 |
|
4719 |
. <br/>
|
4720 |
* @template T object type. <br/>
|
4721 |
* @param a first parameter. <br/>
|
4722 |
* @param b second parameter.</o:p></span></tt></p>
|
4723 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> * @return the larger object<br/>
|
4724 |
*/ </o:p></span></tt></p>
|
4725 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
4726 |
Arial'><o:p><span
|
4727 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
4728 |
"Courier New"'>template <typename T></span></o:p></span></p>
|
4729 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:
|
4730 |
Arial'><o:p><span
|
4731 |
lang=EN-US style='font-size:10.0pt;font-family:fixed;mso-bidi-font-family:
|
4732 |
"Courier New"'>inline const T& max (const T &a, const T &b);</span></o:p></span><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt><span
|
4733 |
lang=EN-US style='font-family:Arial'><o:p></o:p></span></p>
|
4734 |
</td>
|
4735 |
</tr>
|
4736 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4737 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4738 |
<p class=MsoNormal> </p></td>
|
4739 |
</tr>
|
4740 |
</table>
|
4741 |
<p style='margin:0cm;margin-bottom:.0001pt'><span lang=EN-US
|
4742 |
style='display:none;mso-hide:all'><o:p> </o:p></span></p>
|
4743 |
<table class=TableNormal border=1 cellpadding=0 width="100%"
|
4744 |
style='width:100.0%;mso-cellspacing:1.5pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
|
4745 |
<tr style='mso-yfti-irow:0'>
|
4746 |
<td style='background:#BBCCEE;padding:.75pt .75pt .75pt .75pt'>
|
4747 |
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:Arial'>
|
4748 |
100. template class documentation <o:p></o:p></span></b></p></td>
|
4749 |
</tr>
|
4750 |
<tr style='mso-yfti-irow:1'>
|
4751 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4752 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt><tt><span lang=EN-US style='font-size:10.0pt'><o:p>/**</o:p></span></tt></p>
|
4753 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> * @class Stack<br/>
|
4754 |
* @brief template stack class.<br/>
|
4755 |
* detail description.<br/>
|
4756 |
* @template T element type. </o:p></span></tt><tt><span lang=EN-US style='font-size:10.0pt'><o:p><br/>
|
4757 |
*/ </o:p></span></tt></p>
|
4758 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> template <typename T></o:p></span></tt></p>
|
4759 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p>class Stack {</o:p></span></tt></p>
|
4760 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> public: </o:p></span></tt></p>
|
4761 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt></p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> void push(const T& elem ); <br>
|
4762 |
void pop();<br/>
|
4763 |
T top() const;</o:p></span></tt></p>
|
4764 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p> bool empty() const ; </o:p></span></tt></p>
|
4765 |
<p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p></o:p></span></tt></p> <p class=MsoNormal><tt><span lang=EN-US style='font-size:10.0pt'><o:p><tt><span lang=EN-US style='font-size:10.0pt'> </span></tt></o:p></span></tt><span
|
4766 |
lang=EN-US style='font-family:Arial'><o:p><tt><span lang=EN-US style='font-size:10.0pt'> private:</span></tt></o:p></span></p>
|
4767 |
<p class=MsoNormal><span
|
4768 |
lang=EN-US style='font-family:Arial'><o:p><tt><span lang=EN-US style='font-size:10.0pt'> std::vector<T> elems_; <br/>
|
4769 |
};
|
4770 |
</span></tt></o:p></span></p>
|
4771 |
<p class=MsoNormal> </p></td>
|
4772 |
</tr>
|
4773 |
<tr style='mso-yfti-irow:2;mso-yfti-lastrow:yes'>
|
4774 |
<td style='padding:.75pt .75pt .75pt .75pt'>
|
4775 |
<p class=MsoNormal> </p></td>
|
4776 |
</tr>
|
4777 |
</table> <p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
4778 |
line-break'>
|
4779 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
4780 |
<![endif]></span></p>
|
4781 |
<p style='margin-bottom:12.0pt'><span lang=EN-US><br style='mso-special-character:
|
4782 |
line-break'>
|
4783 |
<![if !supportLineBreakNewLine]><br style='mso-special-character:line-break'>
|
4784 |
<![endif]></span></p>
|
4785 |
<h2><a name=References></a><span lang=EN-US>8 References </span></h2>
|
4786 |
<p><a name=ref1></a><span lang=EN-US>[1] Code Complete, Steve McConnel -
|
4787 |
Microsoft Press </span></p>
|
4788 |
<p><a name=ref2></a><span lang=EN-US>[2] Programming in C++, Rules and
|
4789 |
Recommendations, M Henricson, e. Nyquist, Ellemtel (Swedish telecom) <br>
|
4790 |
<a
|
4791 |
href="http://www.doc.ic.ac.uk/lab/cplus/c++.rules/">http://www.doc.ic.ac.uk/lab/cplus/c++.rules/</a>
|
4792 |
</span></p>
|
4793 |
<p><a name=ref3></a><span lang=EN-US>[3] Wildfire C++ Programming Style, Keith
|
4794 |
Gabryelski, Wildfire Communications Inc. <br>
|
4795 |
<a
|
4796 |
href="http://www.wildfire.com/~ag/Engineering/Development/C++Style/">http://www.wildfire.com/~ag/Engineering/Development/C++Style/</a>
|
4797 |
</span></p>
|
4798 |
<p><a name=ref4></a><span lang=EN-US>[4] C++ Coding Standard, Todd Hoff <br>
|
4799 |
<a
|
4800 |
href="http://www.possibility.com/Cpp/CppCodingStandard.html">http://www.possibility.com/Cpp/CppCodingStandard.html</a>
|
4801 |
</span></p>
|
4802 |
<p style='margin-bottom:12.0pt'><a name=ref5></a><span lang=FR
|
4803 |
style='mso-ansi-language:FR'>[5] Doxygen documentation system <br>
|
4804 |
</span><span lang=EN-US><a
|
4805 |
href="http://www.stack.nl/~dimitri/doxygen/index.html"><span lang=FR
|
4806 |
style='mso-ansi-language:FR'>http://www.stack.nl/~dimitri/doxygen/index.html</span></a></span><!--
|
4807 |
*******************************************************************************
|
4808 |
Footer common for all pages
|
4809 |
*******************************************************************************
|
4810 |
--><span lang=FR style='mso-ansi-language:FR'><o:p></o:p></span></p>
|
4811 |
<div class=MsoNormal align=center style='text-align:center'><span lang=EN-US
|
4812 |
style='font-size:10.0pt;font-family:Arial'>
|
4813 |
<hr size=1 width="100%" align=center>
|
4814 |
</span></div>
|
4815 |
<p class=MsoNormal><span lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></p>
|
4816 |
</td>
|
4817 |
</tr>
|
4818 |
<tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes'>
|
4819 |
<td style='padding:6.0pt 6.0pt 6.0pt 6.0pt'>
|
4820 |
<h1><span lang=EN-US><o:p> </o:p></span></h1>
|
4821 |
</td>
|
4822 |
</tr>
|
4823 |
</table>
|
4824 |
|
4825 |
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
|
4826 |
|
4827 |
</div>
|
4828 |
|
4829 |
</body>
|
4830 |
|
4831 |
</html>
|