// 空行
void Function1(…)
{
…
}
// 空行
void Function2(…)
{
…
}
// 空行
void Function3(…)
{
…
}
|
// 空行
while (condition)
{
statement1;
// 空行
if (condition)
{
statement2;
}
else
{
statement3;
}
// 空行
statement4;
}
|
int width; // 寬度
int height; // 高度
int depth; // 深度
|
int width, height, depth; // 寬度高度深度
|
x = a + b;
y = c + d;
z = e + f;
|
X = a + b; y = c + d; z = e + f;
|
if (width < height)
{
dosomething();
}
|
if (width < height) dosomething();
|
for (initialization; condition; update)
{
dosomething();
}
// 空行
other();
|
for (initialization; condition; update)
dosomething();
other();
|
void Func1(int x, int y, int z); // 良好的風格
void Func1 (int x,int y,int z); // 不良的風格
|
if (year >= 2000) // 良好的風格
if(year>=2000) // 不良的風格
if ((a>=b) && (c<=d)) // 良好的風格
if(a>=b&&c<=d) // 不良的風格
|
for (i=0; i<10; i++) // 良好的風格
for(i=0;i<10;i++) // 不良的風格
for (i = 0; I < 10; i ++) // 過多的空格
|
x = a < b ? a : b; // 良好的風格
x=a<b?a:b; // 不好的風格
|
int *x = &y; // 良好的風格
int * x = & y; // 不良的風格
|
array[5] = 0; // 不要寫成 array [ 5 ] = 0;
a.Function(); // 不要寫成 a . Function();
b->Function(); // 不要寫成 b -> Function();
|
void Function(int x)
{
… // program code
}
|
void Function(int x){
… // program code
}
|
if (condition)
{
… // program code
}
else
{
… // program code
}
|
if (condition){
… // program code
}
else {
… // program code
}
|
for (initialization; condition; update)
{
… // program code
}
|
for (initialization; condition; update){
… // program code
}
|
While (condition)
{
… // program code
}
|
while (condition){
… // program code
}
|
如果出現嵌套的{},則使用縮進對齊,如:
{
…
{
…
}
…
}
|
|
if ((very_longer_variable1 >= very_longer_variable12)
&& (very_longer_variable3 <= very_longer_variable14)
&& (very_longer_variable5 <= very_longer_variable16))
{
dosomething();
}
|
virtual CMatrix CMultiplyMatrix (CMatrix leftMatrix,
CMatrix rightMatrix);
|
for (very_longer_initialization;
very_longer_condition;
very_longer_update)
{
dosomething();
}
|
/*
* 函數介紹:
* 輸入參數:
* 輸出參數:
* 返回值 :
*/
void Function(float x, float y, float z)
{
…
}
|
if (…)
{
…
while (…)
{
…
} // end of while
…
} // end of if
|
class A
{
private:
int i, j;
float x, y;
…
public:
void Func1(void);
void Func2(void);
…
}
|
class A
{
public:
void Func1(void);
void Func2(void);
…
private:
int i, j;
float x, y;
…
}
|