Difference between revisions of "Code Formatting Conventions"

Jump to navigation Jump to search
some cleanup and typos
m (→‎Whitespaces: whitespace)
(some cleanup and typos)
Line 5: Line 5:
We don't always follow these rules slavishly, in certain cases it is OK (and in fact might be favorable) to stray from them. Applying common sense, as usual, is a good idea.
We don't always follow these rules slavishly, in certain cases it is OK (and in fact might be favorable) to stray from them. Applying common sense, as usual, is a good idea.


In the following examples tabs are replaced by spaces for visual consistency with the Code Formatting Conventions. But in actual code, use tabs for indentions (our tabs are assumed to be 4 spaces wide).
In the following examples tabs are replaced by spaces for visual consistency with the Code Formatting Conventions. But in actual code, use tabs for indentations (our tabs are assumed to be 4 spaces wide).


== Hugging braces ==
== Hugging braces ==
Line 12: Line 12:


<pre>
<pre>
if (int i = 0; i < t; i++) {
for (int i = 0; i < t; i++) {
    [...]
}
 
if (j < k) {
     [...]
     [...]
} else {
} else {
Line 20: Line 24:
class Dummy() {
class Dummy() {
     [...]
     [...]
}
};
</pre>
</pre>


Line 95: Line 99:
'''Operator overloading'''
'''Operator overloading'''


Operator keyword is NOT seperated from the name, except for type conversion operators where it is required.
Operator keyword is NOT separated from the name, except for type conversion operators where it is required.
<pre>
<pre>
struct Foo {
struct Foo {
2,051

edits

Navigation menu