Open main menu

CDOT Wiki β

Changes

OOP344 - FjXR - 20102

1,358 bytes added, 14:20, 31 May 2010
no edit summary
|}
== Coding Style ==
=== Common Hungarian Notation Prefixes ===
<p>
== Coding Style ==
* reference from the book of "Thinking in C++,Bruce Eckel
=== File names ===
the option of having no file name extension is used,<br/>
i.e.: #include <iostream>.
 
=== Parentheses, braces, and indentation ===
<p>
the opening brace should always go on the same line as the “precursor” (by which I mean
“whatever the body is about: a class, function, object definition, if
statement, etc.”). This is a single, consistent rule I apply to all of the
code I write, and it makes formatting much simpler. It makes the
“scannability” easier – when you look at this line:</p>
<br/>
int func(int a);
<br/>
<br/>
<p>
you know, by the semicolon at the end of the line, that this is a
declaration and it goes no further, but when you see the line:</p>
<br/>
int func(int a) {
<br/>
<br/>
<p>
you immediately know it’s a definition because the line finishes
with an opening brace, not a semicolon. By using this approach,
there’s no difference in where you place the opening parenthesis
for a multi-line definition:</p>
<br/>
int func(int a) {
int b = a + 1;
return b * 2;
}
<br/>
<br/>
<p>and for a single-line definition that is often used for inlines:</p>
<br/>
int func(int a) { return (a + 1) * 2; }
<br/>
<br/>
<p>
Placing the ‘{‘ on the next line eliminates some confusing code
in complex conditionals, aiding in the scannability. Example:
</p>
<br/>
if(cond1<br/>
&& cond2<br/>
&& cond3) {<br/>
statement;<br/>
}<br/>
<br/>
<p>
The above has poor scannability. However,
</p>
<br/>
if (cond1<br/>
&& cond2<br/>
&& cond3)<br/>
{<br/>
statement;<br/>
}<br/>
<br/>
=== Parentheses, braces, and indentation ===
1
edit