C++ Programming Style Guide

TechAges Admin | C++ Training Course | Saturday, September 15th, 2007

This document covers the C++ programming style and practices for C++ development. The establishment of a common style will facilitate in understanding and maintaining code developed by more than one programmers as well as making it easier for maintaining the code by someone who did not actually developed it.

Download C++ Programming Style Guide

Table of Contents:

1.      Introduction

2.      Getting started

2.1.       Pre-processor

2.2.       Macros

2.3.       Conditional Compilation

2.3.1.        Use of #ifdef, #elif, #endif

2.3.2.        Changing Language Syntax

3.      Source Code Files

3.1.       File Naming Convention

3.2.       File Organization

3.3.       Headers

3.3.1.        Header for .h, .hpp and .cpp files

3.3.2.        Method Header

3.4.       Header File Contents

3.4.1.        Order of .h and .hpp File Contents

3.5.       Source File Contents

3.5.1.        Order of .cpp File Contents

4.      Naming Conventions

4.1.       Class

4.2.       Interface

4.3.       Structure

4.4.       Methods

4.4.1.        Method Parameters

4.5.       Variables

4.5.1.        Class Variable

4.5.2.        Pointer Variables

4.5.3.        Static Variables

4.5.4.        Local Variables

4.5.5.        Global Variables

4.6.       Constants

4.7.       Type Names

4.8.       #define and Macros

4.9.       Enum

4.10.          Identifier Name Clashes

5.      Comments

5.1.       Single-Line Comments

5.2.       Trailing Comments

5.3.       Multiple Line Comments

6.      Statements

6.1.       Multiple Statements

6.2.       Compound Statements

6.3.       if else Statements

6.4.       for Statements

6.5.       do Statements

6.6.       while Statements

6.7.       switch Statements

6.8.       try/catch Statements

7.      Indentation

7.1.       Tab Size/Line Spacing

7.2.       Alignment of Braces ‘{ }’

7.3.       Line Breaks

7.4.       Using Parentheses ‘()’

8.      Good Programming Practices

8.1.       No Use of Literal Numbers

8.2.       Avoid Using Macros

8.3.       Preventing Memory Leaks

8.3.1.        Use of Delete Operator

8.3.2.        Use of Virtual Destructors

8.3.3.        Use of Smart Pointers

8.3.4.        Release Existing Memory

8.4.       Using const

8.4.1.        const Object Assignments

8.4.2.        const in Arguments Lists

8.5.       Using enum

References:
[1] Wildfire C++ Programming Style With Rationale by Keith Gabryelski, Wildfire Communications, Inc.
http://www.wildfire.com/~ag/Engineering/Development/C++Style/

[2] C++ Coding Standard by Tom
http://www.cs.umd.edu/users/cml/cstyle/CppCodingStandard.html

[3] C++ Programming Practices by Stan Brown, Oak Road Systems
http://oakroadsystems.com/
 

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

© 2007 TechAges - a customer focused software house in Pakistan