Page 208 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 208
Principles of Software Engineering
Notes • Function names and type names (classes, structs, enum, and typedef) in mixed case,
beginning with uppercase.
• Names of #defines, constants, and enum values in all uppercase, separated with
underscores.
• Global variables start with “g”.
• Class member variables start with “m_”.
Regular Variables
Use mixed case, starting with lowercase. Avoid names that are too short and cryptic, but also
avoid extremely long names. Do not use any prefix (e.g. Hungarian notation), except for the
global variables and pointers.
Global Variables
Global variables should start with ‘g’. The reason is that it is always important to know the scope
of a variable, especially for global variables that have dangerously large scope.
Example gParser, gSimulationClock
Class Names
Use mixed case starting with uppercase. There is no reason to prefix class names with “c” or
“C” to indicate that they are classes, since in a C++ program most data types should be classes,
anyway. Even in the case that you have some non-class types (e.g. struct or enum types), you
want to be able to change them to classes easily, without having to modify their names and
consequently the client code that uses them. Also note that you do not gain any real programming
benefit by embedding in the name the information that something is a class vs. struct or enum
type. It is OK (and very often, advisable) to declare variables with similar name as the class:
FluidSet fluidSet;
Try to limit the number of words you use in class names. Compound names
of over three words are a hint that your design may be confusing various
entities in your system. Revisit your design and try to see if your objects have
more responsibilities than they should.
Class Member Variables
Class member variables should start with “m_”. This increases code readability as it makes it
clear what variables are member variables vs. parameters or locals. Also it allows you to reuse
member variable names as function parameters. The ‘m_’ should always precede other name
modifiers like ‘p’ for pointer.
class Foo {
public:
void Transform(Color color, Flavor flavor) {
m_color = color;
m_flavor = flavor;
}
…
private:
Color m_color;
Flavor m_flavor;
202 LOVELY PROFESSIONAL UNIVERSITY