A short presentation on "bad" C++ given as a lightening talk at the ACCU 2012 conference.
44 slides in 5 minutes? One of my all time records.
Many people have asked for copies of this.
For your reference, all idiotic code here is provided under a "do what you like" license. This license allows you to shoot off for own foot as often as you like. No warranty (express or implied) is given that these code snippets WILL destroy your codebase.
25. const (in)correctness
I said...
void useFoo(const Foo &foo);
Chinese whispers…
void useFoo(Foo &foo); // fred: i had to remove
//constness, as we adjust foo
// before using it
34. the early return
void Foo::DoSomethingAwesome()
{
evilMachinations();
// fred: the app seems to crash with the code below
return;
otherEvilMachinations();
}
36. the helpful comment
void Foo::ItWasBuggyButIFixedItCozIAmGreat()
{
// [geoff] Added this, it was responsible for
// bugs #234 an #9087
if (foo == 23) ...
}
37. the wrong members
don’t use any member variables
static methods placed here because that’s
“where it’s used”
38. making casual friends
class Foo
{
// because we need to get to…
friend class CompletelyUnrelated;
};