Table of Contents
Introduction
This is the coding standard I will use on all my code samples and projects posted on this website. I know a few programming languages, but the one that I use 95% of the time is C++, so it seems like using it as a reference for this standard is the obvious choice. Enjoy!
Why have a Standard?
After programming for a few years, I have used many different programming styles due to having multiple instructors, using different IDEs or Text editors, and various programming languages. It has been great experiencing all these different styles and conventions to understand why some are better than others or simply which ones work better for me. The need for a standard comes from me trying to unify my code so that I can present it here on my website or upload libraries that I make, all using the same coding standards to make it easier for people other than me to read. I’m also making it because I believe it’s a great experience and it’ll force me to do some research on different styles from other coding standards published publicly all over the web, and end up with very clean and readable code. Lastly, I am writing it because it sounds fun!
[top]
Terminology
In order to avoid confusion and explaining myself over and over again, here’s a list of terms I will be using troughout this page:
-
Pascal Case: Also called Upper Camel Case, it’s a special case of Camel Case where the first letter always is Uppercase (as opposed to Camel Case, where it can be either Upper or Lower case) and then every first letter of the following words is capitalized as well, including 1-letter words. Microsoft started using this term and I like that it makes it a little less wordy than “Upper Camel Case” or “Lower Camel Case”. Examples:
Pascal // 1 word WriteAText // 1-letter word (A) CheckEveryInstance // Multiple words
-
Camel Case: Also called Lower Camel Case. The first letter of the first word is written in lowercase, while all other words have their first letter capitalized, including 1-letter words. Examples:
camel // 1 word setATime // 1-letter word numWords // Multiple words
-
Hungarian Notation: It’s a naming convention used in programming where we use prefixes to indicate the type of intended use of a variable or function. Examples:
Sprite* pPlayer; // Pointer to the player Sprite Time& rStartTime; // Reference to a Time object long lNumObjects; // NumObjects is stored in a long int
-
All Caps: Meaning every letter in a word is capitalized. If there are multiple words, they need to be separated using underscores (_). Examples:
ROUND // 1 word MAKE_NODE_LEFT // Multiple words
CHECKKEYBOARDINPUT // Not OK -
Allman Style: Indenting style where the opening brace is opened in the line following a control statement, indented to the same level as the control statement. Every element inside of that control statement is indented in between the braces. The closing brace is put on a line of its own after all the statements. Example:
for (int i = 0; i < count; ++i) { DoFirstThing(); DoSecondThing(); } DoThirdThing();
Style Preference
Most of the conventions talked about in this page are meant to increase readability, make code less prone to have bugs and make it more efficient. There are some standards that I will be talking about though that are purely for the sake of aesthetics and is subjective from person to person. This is my personal style and I will explain why I chose it, but it will mostly be due to personal preference or the coding environment (IDE, Text Editor, etc) that I use, which gives me easy options to adopt that style or has some advantage of some sort (like code folding for comments, IntelliSense, etc). I am open for discussion on any of these matters and maybe I will update the Standard and adopt a new style if given a good reason to do so. After all, programming is an ever-changing art and I will most likely continue to tweak my style over the years.
[top]
References
While writing this Standard, I used a few other standards scattered around the web as reference as well as my personal experience. These are the other Coding Standards I looked at for reference:
- Google C++ Style Guide
- Juce Coding Standards
- Mantid C++ Coding Standards
- Joint Strike Fighter: C++ Coding Standards
- Insomniac Games Core Coding Standard
- C++ Coding Standard
- Stroustrup’s Personal Website (Creator of C++)
- Professor Matthew Mead’s teachings
ChangeLog
List of changes made to this page:
08/03/14 —– Created the Coding Standard
Naming
This is the coding standard I will use on all my code samples and projects posted on this website. I know a few programming languages, but the one that I use 95% of the time is C++, so it seems like using it as a reference for this standard is the obvious choice. Enjoy!