织梦CMS - 轻松建站从此开始!

罗索

C++ Coding Rules under Win32

罗索客 发布于 2001-11-08 21:51 点击:次 
作为一名专业的软件开发人员,我在编程实践中认识到,在开发中贯彻一定的程式开发准则,会使你的程式易维护、少错误,同时能够增强程序的团队开发性。使程序的专业化程度大大提高。现在我将我在程序设计中总结的Coding Rule列举于下
TAG:

前言:
作为一名专业的软件开发人员,我在编程实践中认识到,在开发中贯彻一定的程式开发准则,会使你的程式易维护、少错误,同时能够增强程序的团队开发性。使程序的专业化程度大大提高。现在我将我在程序设计中总结的Coding Rule列举于下:
内容:C++ Coding Rules under Win32
一.相关文档注释要求:
1.Every file that contains source code must be documented with an introductory comment that provides information on the file name and its contents.
2.Every definition of class must be documented with detail comment concerning about purpose, basic algorithm, author, revision history. And each member data should be given a full description.
3.All function except those generated by framework should be documented with purpose, parameters and return value.
4.Assign easy-reasonable name and leave full description behind the definition of the name.
5.Use parentheses to clarify the order of evaluation for operators in expressions.
二.程序编写注意事项: 
 编程基本规则: 
1.All public functions should be referenced by other classes.
2.Never specify public member data in a class.
3.A public member function must never return a non-const reference    or pointer to member data.
4.Avoid global data if at all possible.
    说明:可以在C*App类中指定,然后使用AfxGetApp()->***来使用
5.Assign appropriate type for each variable (尽量减少浪费) ,Variables are to    be declared with the smallest possible scope.
6.Utilize reference parameters instead of pointer parameters.(自定规则)
7.Place the order of parameters as INPUT ones, OUTPUT ones and INPUT ones.    (INPUT, INPUT/OUTPUT, OUTPUT)(自定规则)
8.Avoid the use of numeric values in code; use symbolic values instead.
9.Do not write logical expressions of the type if(test) or if(!test) when   test is a pointer.
说明:
  在如上写法中,test最好仅为BOOL型变量。指针仍以         用!=NULL,==NULL为佳    最好勿将函数整个写在此判断中。
10.Do not use "goto".
11.Every variable that is declared is to be given a value before it is used.
12.Definitions of classes that are only accessed via pointers (*) or references (&)    shall not be included as include files.
说明:使用一个类,在可能的情况下,应将类包含在使用者的.cpp文件中,避   免重复包含。  如果必须在使用者的.h文件中包含此类的头文件,应使用ifdef...语句避   免重复包含。
13.All classes which are used as base classes and which have virtual functions, must define a virtual destructor.
14.For uninstallation, we shoule remove all our own created DLLs or any others libraries (lib, OCX,..) if there is not application used it anymore.
15.Under VC, Set the compile option "Warning level" to "Level 4" .(on the page of VC-> Project->settings...->C/C++)
16.define structures' name in "upper case"
17.Add "::" before API functions VOID(instead of void) 禁止使用char,一般使用TCHAR 不主张使用CPoint,CRect,用POINT,RECT代替。
内存相关问题:
18.Every function that allocate system's resources should return result boolean        code. And this result should always be checked
19.Pointer problem:  定义Pointer时:将Pointer初始化置空(NULL)。 任何时候使用Pointer时,均先判断它是否为空,为空则应相应处理。 分配内存前,先判断是否非空,为非空先删去置空。 分配内存后,马上判断是否分配成功(Pointer!=NULL),为空则相应处理。 .释放指针时,判断是否非空,非空则先删去(delete),再置空。
20.Use new and delete in memory allocation and de-allocation.
21.在分配内存(如图形结构...)时,应该先使用Memset(..)等函数赋值内 存。
       Exm:
               BITMAP bm;
               memeset(&bm,0,sizeof(BITMAP));

结束语:希望能有更多的人关注Coding Rule,让我们的程式更优秀、更专业。有不同的意见或补充,请与我联系
E-Mail:DavidZheng@aps.com.cn

(DavidZheng)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200111/944.html]
本文出处:网络博客 作者:DavidZheng
顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容