What are the coding conventions used in the source?



One of the greatest books I've ever read on programming was Code Complete (Microsoft Press). It's a handbook on how to program well (not just how to program). Nuances like the length of variable names, design of subroutines, and length of files are covered in detail in this book; I strongly encourage anyone who wants to become a great programmer to pick it up. You may notice that some of the conventions I use in this book are similar to the conventions described in Code Complete; some of them are borrowed from the great game programmers like John Carmack, and some of them are borrowed from source in DirectX, MFC, and Win32.
I've tried really hard to make the code in this book accessible to everyone. I comment anything I think is unclear, I strive for good choice in variable names, and I try to make my code look clean while still trying to be fast. Of course, I can't please everyone. Assuredly, there are some C++ coding standards I'm probably not following correctly. There are some pieces of code that would get much faster with a little obfuscation.
If you've never used C++ before or are new to programming, this book is going to be extremely hard to digest. A good discussion on programming essentials and the C++ language is C++ Primer (Lippman et al.; Addison-Wesley Publishing).
17
Class/Structure Names
MFC names its classes with a prefixed C. As an example, a class that represents the functionality of a button is called CButton. I like this fine, but due to namespace clashing, I instead prefix my own classes with a lowercase c for classes, a lowercase s for structs, a lowercase i for interfaces, and a lowercase e for enumerations (cButton or sButton).
There is one notable exception. While most classes are intended to hide functionality away and act as components, there are a few classes/structures that are intended to be instantiated as basic primitives. So for basic mathematic primitives like points and matrices, I have no prefix, and I postfix with the dimension of the primitive (2D points are point2, 3D points are point3, etc.). This is to allow them to have the same look and feel as their closest conceptual neighbor, float. For the same reason, all of the mathematic primitives have many overloaded operators to simplify math-laden code.

Post a comment

0 Comments