Good Practices

Many details make up a “good” program. The following is just a start towards listing them. The items below are considered in the grading of a class project.

Creating a list of these is not easy, as there are always exceptions. However, these exceptions are not common. Think about where this would apply, not what the exception would be.

The checklist will be extended as the semester progresses.

Files and Directories

Indentation and Spacing

Overall Program

Naming

Statements

Functions

std::string

The std::string default constructor initializes to an empty string. So instead of:

just declare the string:

A std::string is a (specialized) container. Use container methods over comparison. So instead of:

just check that it is empty, just like other containers:

One exception might be if you are in a set of if statements (such as a nested if) and are comparing the string to other literal strings.

Also, if you need to change to value to an empty string, instead of:

just clear out the data, just like other containers:

Parameter Types

Direction Primitive Object
IN T const T&
OUT, IN/OUT T& T&

Examples:

As always, some specific cases:

Comments

The following applies to all comments, except file header comments.