Line, SavingsAccount
line, savingsAccount
MAX_ITERATIONS, COLOR_RED, PI
getName(), computeTotalWidth()
model::analyzer, io::iomanager, common::math::geometry
template<class T> ... template<class C, class D> ...
exportHtmlSource(); // NOT: exportHTMLSource(); openDvdPlayer(); // NOT: openDVDPlayer();
Using all uppercase for the base name will give conflicts with the naming conventions given above. A variable of this type whould have to be named dVD, hTML etc. which obviously is not very readable.
Another problem is illustrated in the examples above; When the name is connected to another, the readbility is seriously reduced; the word following the abbreviation does not stand out as it should.
::mainWindow.open(), ::applicationContext.getName() In general, the use of global variables should be avoided. Consider using singleton objects instead.
class SomeClass { private: int length_; }
void setTopic(Topic* topic) // NOT: void setTopic(Topic* value) // NOT: void setTopic(Topic* aTopic) // NOT: void setTopic(Topic* t) void connect(Database* database) // NOT: void connect(Database* db) // NOT: void connect (Database* oracleDB) Non-generic variables have a role. These variables can often be named by combining role and type: Point startingPoint, centerPoint; Name loginName;
fileName; // NOT: filNavn
line.getLength(); // NOT: line.getLineLength();
employee.getName(); employee.setName(name); matrix.getElement(2, 4); - The term compute can be used in methods where something is computed.<code> valueSet->computeAverage(); matrix->computeInverse() this is a potential time consuming operation, and if used repeatedly, consider caching the result. - The term find can be used in methods where something is looked up.<code> vertex.findNearestVertex(); matrix.findMinElement(); this is a simple look up method with a minimum of computations involved.
printer.initializeFontSet();
mainWindow, propertiesDialog, widthScale, loginText, leftScrollbar, mainForm, fileMenu, minLabel, exitButton, yesToggle etc.
vector<Point> points; int values[];
nPoints, nLines - The suffix No should be used for variables representing an entity number.<code> tableNo, employeeNo An elegant alternative is to prefix such variables with an i: iTable, iEmployee. This effectively makes them named iterators.
for (int i = 0; i < nTables); i++) { : } for (vector<MyClass>::iterator i = list.begin(); i != list.end(); i++) { Element element = *i; ... }
isSet, isVisible, isFinished, isFound, isOpen There are a few alternatives to the is prefix that fits better in some situations. These are the has, can and should prefixes: bool hasLicense(); bool canEvaluate(); bool shouldSort();
get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, old/new, open/close, show/hide, suspend/resume, etc.
computeAverage(); // NOT: compAvg();
Line* line; // NOT: Line* pLine; // NOT: LIne* linePtr;
bool isError; // NOT: isNoError bool isFound; // NOT: isNotFound
enum Color { COLOR_RED, COLOR_GREEN, COLOR_BLUE };
An alternative approach is to always refer to the constants through their common type: Color::RED.
class AccessException { : }