VC++, C#, VB.NET Coding Guideline of All-In-One Code Framework

The coding standards for native C++ and .NET (C# and VB.NET) programming used by the All-In-One Code Framework team is now available to everyone. The Microsoft All-In-One Code Framework project team writes code samples based on this guideline.

Download:

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. :-)

!

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

This article is part of the GWB Archives. Original Author: Geekswithblogs

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.