代码改变世界

VC++, VC#, VB.NET 编码规范 (微软一站式示例代码库)

2010-08-12 10:38  Jialiang  阅读(4099)  评论(23编辑  收藏  举报

经过三个月的不懈努力和反复检查,我们项目组终于完成了一份80页的VC++, VC#, VB.NET 编码规范。所有一站式示例代码库里的示例代码将以此为标准进行编写。我也希望这份编码规范能或多或少帮助到博客园里的朋友们编写更加优质统一的代码。

 

下载地址:http://1code.codeplex.com/releases/50431/download/141770

 

 


该文档主要分为三块:

General Coding Standards (即VC++, VC#, VB.NET 共通的一些编码规范)

C++ Coding Standards (C++ 特有的编码规范)

.NET Coding Standards (VC#, VB.NET 特有的编码规范)

 

该文档编写过程中得到了不少微软专家级开发工程师的审阅。文档中包含不少产品组使用的编码 best practices。比如:

Do use sizeof(var) instead of sizeof(TYPE). To be explicit about the size value being used whenever possible write sizeof(var) instead of sizeof(TYPE_OF_VAR). Do not code the known size or type of the variable. Do reference the variable name instead of the variable type in sizeof:

    Good:

    MY_STRUCT s;

    ZeroMemory(&s, sizeof(s));

    Bad:

    MY_STRUCT s;

    ZeroMemory(&s, sizeof(MY_STRUCT));

Do not use sizeof for arrays to get the element number. Use ARRAYSIZE.

 

这份编码规范仍在不断改进。如果你注意到一些good coding practice没有被记录在这份文档里,请告知我们: onecode@microsoft.com. 定予以重谢! :-)