Super Game Engine Pre-alpha Help

Naming Standards | C Plus Plus Standards

Summary

These are the standards for naming within C++ documents across SGE products.

1. United Kingdom Based English

Where spelling differs among US and UK English, UK english is to be used.

1. Example

// Should not be class color { } // Should be class colour { }

1. Reason

Consistency has to be established and the founder is from the United Kingdom and therefore the foundational files have been named in this manner.

2. Classes, Structs, Enums and Methods begin with a Capital Alphabetical Character

All classes, structs, enums and methods must begin with a letter from A to Z nothing else. They must also begin with a capital letter.

2. Example

// Bad Examples class hello; class goodbye; class _the; class _12345; // Acceptable class Hello; class Goodbye; class The; class One2345;

2. Reason

It is important to expect an external object types to conform to a certain structural naming scheme.

3. Types and Methods (Classes, Enums, Structs) are named Upper CamelCase

All classes, structs, enums, methods and types such as any exception types must be named upper CamelCase.

3. Example

// Bad Examples class hellogoodbye; class goodbye; class ThenewWorld class Why_Not_UnderScores // Acceptable class HelloGoodbye; class TheNewWorld class BecauseNoPleaseNo

3. Reason

Upper camel case keeps the line length small whilst leaving text easy to read. There are a few exceptions to this rule but they are called out explicitly.

4. Private Member properties / fields are prefixed m underscore

All member properties, meaning private variables stored by a class but not accessible by externals are prefixed with an m_

4. Example

// Bad Example class example { private: int number; std::string somethingElse; } // Good Example class Example { private: int m_number; std::string SomethingElse; }

4. Reason

It is easier to figure out the origin of a variab le with the prefix. This is especially true when looking at the code via review software or diffing software.

5. Public Variables are named UpperCamelCase

Although these should be avoided in general, if there cases for public variables in a class, name them with UpperCamelCase no underscores or anything else.

5. Example

class Example { public: int MyNumber; }

5. Reason

A public variable may as well be a method or other such vulnerability within a given class as anything externally could access it. This means two things, firstly external objects should expect interactions with classes as UpperCamelCase and that the likelihood it changes to a method to be higher than other sections of code (as functionality increases). As this consonance of name is spread around it minimizes the amount of change to already name the variable in such a way as to imply it is public and vulnerable to change from the outside world.

Last modified: 04 April 2024