650
备注:
|
1675
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 3: | 行号 3: |
* 先写注释再写代码,规范化的注释。按照doxygen的标准给类、函数、变量写注释。 | * 先写注释再写代码,规范化的注释。按照doxygen的标准给类、函数、变量写注释。比如,类似的注释一点用处都没有:{{{#!cplusplus //---------------------------------------------------------------------------- // @ SimDoor::SimDoor() // --------------------------------------------------------------------------- // Constructor //---------------------------------------------------------------------------- SimDoor::SimDoor( const RSString& name ) }}}再比如{{{#! }}}比较好的写法应该类似这样:{{{#!cplusplus /// \brief check the block is saved or not /// \author Chen Zhongke /// \param filename the filename of the block data file. /// \result return -1 if filename doesn't exist, otherwise return the index of the file in buffer. int SimulateIsSaved(RSString filename); }}}对于函数的注释应该写在头文件的声明中,而不是定义中。 |
行号 5: | 行号 21: |
* 避免使用预编译 | * 避免使用预编译{{{#!cplusplus #define kMaxFriends 2 }}}应该定义成{{{ static const int kMaxFriends = 2; }}}并写在用到它的类中,而不是一个全局的常量。 |
行号 12: | 行号 32: |
* 注意Singleton模式的实现。 |
some tips on writing c++ codes to avoid potential bugs:
先写注释再写代码,规范化的注释。按照doxygen的标准给类、函数、变量写注释。比如,类似的注释一点用处都没有:
1 //---------------------------------------------------------------------------- 2 // @ SimDoor::SimDoor() 3 // --------------------------------------------------------------------------- 4 // Constructor 5 //---------------------------------------------------------------------------- 6 SimDoor::SimDoor( const RSString& name )
再比如
比较好的写法应该类似这样:
对于函数的注释应该写在头文件的声明中,而不是定义中。- 避免重复代码,使用函数。
避免使用预编译
应该定义成
static const int kMaxFriends = 2;
并写在用到它的类中,而不是一个全局的常量。- 避免switch,用数据来简化代码
- 注意代码统计质量,函数不可太长,方法不可太多,不可有太多子类,不可有太多父类
- 避免指针,避免数组,避免自己写常用的数据结构,用stl
- 避免用C++实现OO design,注意对象的owner
- 善用svn,大的修改应该建分支
- 速度至关重要时,用查表代替计算,避免浮点数,
- 注意Singleton模式的实现。