All-In-One Code Framework Coding Guideline

This document describes the coding style guideline for native C++ and .NET (C# and VB.NET) programming used by the Microsoft All-In-One Code Framework project team.
 
 
Table of Contents

1      Overview.......................................................................................................................... 1

1.1      Principles & Themes................................................................................................. 1

1.2      Terminology................................................................................................................ 1

2      General Coding Standards........................................................................................ 3

2.1      Clarity and Consistency........................................................................................... 3

2.2      Formatting and Style................................................................................................ 3

2.3      Using Libraries........................................................................................................... 5

2.4      Global Variables........................................................................................................ 5

2.5      Variable Declarations and Initalizations............................................................. 5

2.6      Function Declarations and Calls............................................................................ 6

2.7      Statements................................................................................................................... 8

2.8      Enums............................................................................................................................ 8

2.9      Whitespace................................................................................................................ 13

2.10   Braces........................................................................................................................... 14

2.11   Comments................................................................................................................... 15

2.12   Regions........................................................................................................................ 23

3      C++ Coding Standards............................................................................................ 25

3.1      Compiler Options................................................................................................... 25

3.2      Files and Structure.................................................................................................. 26

3.3      Naming Conventions............................................................................................. 27

3.4      Pointers...................................................................................................................... 30

3.5      Constants................................................................................................................... 31

3.6      Casting....................................................................................................................... 32

3.7      Sizeof.......................................................................................................................... 32

3.8      Strings........................................................................................................................ 33

3.9      Arrays......................................................................................................................... 34

3.10   Macros........................................................................................................................ 35

3.11   Functions..................................................................................................................... 35

3.12   Structures................................................................................................................... 38

3.13   Classes........................................................................................................................ 38

3.14   COM............................................................................................................................ 44

3.15   Allocations.................................................................................................................. 45

3.16   Errors and Exceptions............................................................................................. 46

3.17   Resource Cleanup..................................................................................................... 48

3.18   Control Flow................................................................................................................ 50

4      .NET Coding Standards............................................................................................. 54

4.1      Design Guidelines for Developing Class Libraries........................................ 54

4.2      Files and Structure................................................................................................... 54

4.3      Assembly Properties............................................................................................... 54

4.4      Naming Convensions............................................................................................. 54

4.5      Constants................................................................................................................... 57

4.6      Strings......................................................................................................................... 58

4.7      Arrays and Collections........................................................................................... 59

4.8      Structures.................................................................................................................... 61

4.9      Classes......................................................................................................................... 62

4.10   Namespaces................................................................................................................ 65

4.11   Errors and Exceptions.............................................................................................. 65

4.12   Resource Cleanup...................................................................................................... 68

4.13   Interop........................................................................................................................... 80

Each chapter in this document has to acknowledge Dan Ruder, a Principal Escalation Engineer of Microsoft. Dan carefully reviewed every word, and contributed review comments on significant portions of the book based on his more than 20 years’ programming experience. Working with the nice man has been a special treat to me.

I also thank four managers at Microsoft for continuously supporting and sponsoring the work: Vivian Luo, Allen Ding, Felix Wu and Mei Liang.

This document wouldn’t contain the depth of technical details or the level of completeness it has without the input of the following people

Alexei Levenkov , Hongye Sun, Jie Wang, Ji Zhou, Michael Sun, Kira Qian, Allen Chen, Yi-Lun Luo, Steven Cheng, Wen-Jun Zhang, Linda Liu

Some chapters derive from several Microsoft product teams’ coding standards. I appreciate their sharing.

The coding standards are continuously evolving. If you discover a new best practice or a topic that is not covered, please bring that to the attention of the All-In-One Code Framework Project Group (onecode@microsoft.com). I look forward to appreciating your contributions.  :-)

Last edited Mar 22, 2012 at 11:00 AM by Jialiang, version 27

Comments

askitanna Oct 4, 2011 at 2:07 PM 
@Dave4125 Thank you,

Dave4125 Aug 25, 2011 at 4:48 PM 
Click on the "This document" link instead of the link next to the Chinese characters.

http://1code.codeplex.com/releases/view/62267#DownloadId=215635

jimsing59 Aug 9, 2011 at 3:58 PM 
Try using Google Translate or go to Chinatown.

kamleshrao Jul 29, 2011 at 1:49 PM 
Hello, The word document that I downloaded is in Chinese language. Where can I find the English version of this document.