Last Edited: Wed Jan 24 08:14:31 1996 by jnw (Joseph N. Wilson) on aviator.cis.ufl.edu

CIS 4930 Section 0998X (Spring 1996)

Object-Oriented Programming

C++ Coding Standards

The Role of Coding Standards

Coding standards are employed in programming organizations to support

Because a shop uses certain coding standards, that does not mean that either

It is merely a way of providing uniformly readable code.

Coding standards come in many forms. I will attempt to eschew the use of textual formatting coding standards and will impose them only if I find programs to be extremely difficult to read.

Our Coding Standards

The Coding Standards provided below must be followed in writing programs you turn in. If code examples shown by the instructor do not satisfy the coding standards, you are expected to call it to his attention.

Each header file (file.h) must begin with
#ifndef file_h_ #define file_h_
and end with
#endif
This is the only transportable way to guarantee that no multiple inclusions will take place.
All instance variables (member data) of a class must be private. Access to getting/setting them must be through functions (even within the class).
If these are not private, then the class interface restrictions cannot be enforced.
Parameters in a function declaration (even for a member function) must have variable names matching their names in the associated function definition.
If parameter names are not provided, the user can misunderstand the intent of a function.
A default constructor must be provided for each class. (It can be private.)
If one is not provided by the programmer then uninitialized objects can be created.
A copy constructor must be provided for each class. (It can be private.)
If no copy constructor is provided, then a default is generated. It might not have the right behavior.
An assignment operator must be provided for each class. (It can be private.)
If no assignment operator is provided, then a default is generated. It might not have the right behavior.
All public constructors must initialize every data member.
If data members are not initialized explicitly, their values are unknown. It's unsafe to use such fields.

This document is copyright 1996 by Joseph N. Wilson.