docs: update coding style

This commit is contained in:
Liu Chao
2018-05-06 16:10:22 +08:00
parent 17eb2c0797
commit 4e4d211963
3 changed files with 4 additions and 90 deletions
-1
View File
@@ -1,4 +1,3 @@
Please read the file `README.md`.
请阅读中文版的README文件:`README.zh-cn.md`.
+4 -10
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
@@ -22,9 +21,6 @@
<Filter Include="头文件\LCUI\font">
<UniqueIdentifier>{e82633f2-1d26-4ccb-9d8b-acf3bca828a4}</UniqueIdentifier>
</Filter>
<Filter Include="docs">
<UniqueIdentifier>{55f58a5e-9a60-4e9d-b65e-7377c4486a7f}</UniqueIdentifier>
</Filter>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
@@ -490,13 +486,11 @@
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\README" />
<None Include="..\..\..\README.md" />
<None Include="..\..\..\README.zh-cn.md" />
</ItemGroup>
<ItemGroup>
<Text Include="..\..\..\LICENSE.TXT" />
<Text Include="..\..\..\README" />
<Text Include="..\..\..\README.md" />
<Text Include="..\..\..\README.zh-cn.md" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="LCUI.rc">
-79
View File
@@ -24,57 +24,6 @@
在源文件里,使用空行隔开不同的函数。
## 集中的函数退出途径
虽然被某些人声称已经过时,但是goto语句的等价物还是经常被编译器所使用,具体形式是无条件跳转指令。
当一个函数从多个位置退出并且需要做一些通用的清理工作的时候,goto的好处就显现出来了。
理由是:
- 无条件语句容易理解和跟踪
- 嵌套程度减小
- 可以避免由于修改时忘记更新某个单独的退出点而导致的错误
- 减轻了编译器的工作,无需删除冗余代码
```c
int fun(int a)
{
int result = 0;
char *buffer;
buffer = malloc(SIZE);
...
if( ... ) {
result = -1;
goto error_out;
}
...
if( ... ) {
result = -2;
goto error_out;
}
...
while (1) {
for( ... ) {
for( ... ) {
if( ... ) {
result = -3;
goto error_out;
}
}
}
}
...
return 0;
error_out:
...
free(buffer);
return result;
}
```
## 命名规范
### 类型命名
@@ -125,34 +74,6 @@ int Foo_GetName( LCUI_Foo foo );
构造函数与对象类型名称相同,返回该对象的句柄引用。对象的析构函数名称则是类型名称附加 `_Delete` 后缀。其它与该对象相关的操作函数名则都以 `Foo_` 开头。
## 空格
调用函数时,每个参数的逗号后面需要加个空格,括号左右内侧也需要加空格。
``` c
func( arg1, arg2, arg3, arg4 );
```
if、while、for 的括号内两侧、左花括号左侧需要加上空格。
``` c
if( 100 > 0 ) {
...
} else {
...
}
while( 1 ) {
...
}
```
运算符两侧需要加上空格。
``` c
a = b + c * d / 100 >> 2;
```
## 注释
**函数注释:** 如果是在头文件中有声明的公用函数,那么函数注释只需要在头文件的函数声明中写上,而源文件中可以不用重复写注释,这样可以省去同时维护两个注释的麻烦。