- #include "file.cpp"
- Declaring fields as protected with a comment stating that a friend class is the only one who should access them.
- Allocating an object using new instead of on the stack because it must be passed by pointer to a function and the programmer doesn't know that they should use the address-of (&) operator.
- Having two functions foo(A*) and foo(A&) that are copy-and-paste identical save for using -> instead of . because the programmer didn't realize how to convert references to pointers and vice versa.
- Making fields public via by-reference getter and setter.
- Thinking copy-and-paste == code reuse.
- Using "string const &" instead of "const string&"
- Implementation in header files
- if (p) delete p;
- if (b == true), if (b == false)
- if (v.size() == 0)
- "using namespace" in header files
- Using vector
to represent a rectangle - v[15].first.second.first[5].WhatTheHeckAmIAnyway()
- Passing user-defined objects by value
- for(int i = 0; i < n; ++i) { if (i == 5) a[i] = 0; }
Thursday, February 23, 2012
C++ Programming Anti-Patterns and Annoyances
Subscribe to:
Posts (Atom)