An interesting discussion broke out on comp.lang.c++.moderated recently. I thought I'd share the topic here and see what people thought about it. (I hope I'm not breaking forum rules by doing so.)
What are your C++ pet-peeves?
Here's what other people have listed:
Performance related pet-peeves
* people using const references to pass ints and bools
* consecutive streaming statements to the same stream, especially when they flush the stream unnecessarily:
* Initialized variables that are immediately overwritten:Code:cout << "a " << a << endl;
cout << "b " << b << endl;
Code:bool x = false;
x = MyFuntion();
Unnecessary code pet-peeves
* Checking if a container is empty before iterating over it:
* Using "v.size() == 0" or "v == std::vector<int>()" instead of simply "v.empty()"Code:if ( !v.empty() )
{
for ( v::iterator i ...)
...
;
}
Reliving C pet-peeves
* Always defining a structure this way:
[code]
typedef struct _StructName
{
// data members
}StructName;
[code]
* Using macro constants rather than C++ constants:
* Testing bools against true/falseCode:#define SOME_CONSTANT 5 // int const some_constant = 5;
* Using C <string.h> functions instead of C++ string operations:Code:if (some_bool != false) // use: "if (some_bool)"
* Attempting to use C++ "features" when not needed just to make it look like you know C++Code:std::string s1;
std::string s2;
if(strcmp(s1.c_str(),s2.c_str())!=0)
{}
Code:class IHaveASimpleCFunction
{
public:
IHaveASimpleCFunction() {} // do nothing
void operator()()
{
// do what needs to be done
}
};
int main()
{
IHaveASimpleCFunction i;
i();
return 0;
}
