C++ THE CATHEDRAL       &  THE BIZARREPETE GOODLIFFE pete@goodliffe.net @petegoodliffe
@petegoodliffepete@goodliffe.netgoodliffe.blogspot.comwww.goodliffe.net      P ETE GOOD      PROGRAMME                 LIF...
semicolon overload
void foo(){};class Foo{public:   Foo() { /* blah */ };};
the non-virtual destructor      class Foo      {      public:         virtual void doSomething() = 0;      };   it’s just ...
being very certain   if (foo == true) doFoo();
being surprisedif (foo && bar || baz) doFoo();
very careful delete     if (foo) delete foo;
looking like code void foo(Thing &t) {   Component *source = t.source;   {      return true;   }   return false; }
in(line) sanityin .h...  class Foo  {  public:     void MyMethod();  };in .cpp:  inline void Foo::MyMethod()  { /* do tonn...
the namespace class
not using initialiser lists
wrong order initialiser lists
any warnings
the wrong type of   inheritance
writing your own list
or pair
or string
or list
or...
const (in)correctnessI said...void useFoo(const Foo &foo);Chinese whispers…void useFoo(Foo &foo); // fred: i had to remove...
delete disaster int *foo = new int [10]; delete foo;
doing nothing in stylebool Foo::ThingChanged(Thing *param, int value){  switch(param->GetTag())  {     default:        bre...
rule of three
stupid long functions
ascii art “standard” header /*------------------------------------------------------------   Function:   Enter:   Exit:   ...
just one more parameter      it’s only wafer theeeen...
the early returnvoid Foo::DoSomethingAwesome(){  evilMachinations();    // fred: the app seems to crash with the code belo...
inconsistency       naming       spacing  pointers/references
the helpful commentvoid Foo::ItWasBuggyButIFixedItCozIAmGreat(){  // [geoff] Added this, it was responsible for  // bugs #2...
the wrong members    don’t use any member variablesstatic methods placed here because that’s            “where it’s used”
making casual friends class Foo {    // because we need to get to…    friend class CompletelyUnrelated; };
leaving helpful notesor questions in the code     //fred: why set it to 24????
protected member variables         for convenience
commenting out code     large swathes of it
calling everything foo
@petegoodliffepete@goodliffe.netgoodliffe.blogspot.comwww.goodliffe.net
BUMPH DULL, but important                            ★THIS DOCUMENT WAS CREATED BY PETE GOODLIFFE    IT IS COPYRIGHT // © ...
C++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
C++: The Cathedral and the Bizarre
Upcoming SlideShare
Loading in...5
×

C++: The Cathedral and the Bizarre

801

Published on

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.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
801
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

C++: The Cathedral and the Bizarre

  1. 1. C++ THE CATHEDRAL & THE BIZARREPETE GOODLIFFE pete@goodliffe.net @petegoodliffe
  2. 2. @petegoodliffepete@goodliffe.netgoodliffe.blogspot.comwww.goodliffe.net P ETE GOOD PROGRAMME LIFFE R / AUTHOR / COLUMNIST / TEACHER ★ CON SCIENTIOUS CODER
  3. 3. semicolon overload
  4. 4. void foo(){};class Foo{public: Foo() { /* blah */ };};
  5. 5. the non-virtual destructor class Foo { public: virtual void doSomething() = 0; }; it’s just common sense, come on people
  6. 6. being very certain if (foo == true) doFoo();
  7. 7. being surprisedif (foo && bar || baz) doFoo();
  8. 8. very careful delete if (foo) delete foo;
  9. 9. looking like code void foo(Thing &t) { Component *source = t.source; { return true; } return false; }
  10. 10. in(line) sanityin .h... class Foo { public: void MyMethod(); };in .cpp: inline void Foo::MyMethod() { /* do tonnes of stuff */ }
  11. 11. the namespace class
  12. 12. not using initialiser lists
  13. 13. wrong order initialiser lists
  14. 14. any warnings
  15. 15. the wrong type of inheritance
  16. 16. writing your own list
  17. 17. or pair
  18. 18. or string
  19. 19. or list
  20. 20. or...
  21. 21. const (in)correctnessI 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
  22. 22. delete disaster int *foo = new int [10]; delete foo;
  23. 23. doing nothing in stylebool Foo::ThingChanged(Thing *param, int value){ switch(param->GetTag()) { default: break; } return true;}
  24. 24. rule of three
  25. 25. stupid long functions
  26. 26. ascii art “standard” header /*------------------------------------------------------------ Function: Enter: Exit: Notes : ----------------------------------------------------------*/ void Foo::DoThing(Thing *pThing) { //… stuff
  27. 27. just one more parameter it’s only wafer theeeen...
  28. 28. the early returnvoid Foo::DoSomethingAwesome(){ evilMachinations(); // fred: the app seems to crash with the code below return; otherEvilMachinations();}
  29. 29. inconsistency naming spacing pointers/references
  30. 30. the helpful commentvoid Foo::ItWasBuggyButIFixedItCozIAmGreat(){ // [geoff] Added this, it was responsible for // bugs #234 an #9087 if (foo == 23) ...}
  31. 31. the wrong members don’t use any member variablesstatic methods placed here because that’s “where it’s used”
  32. 32. making casual friends class Foo { // because we need to get to… friend class CompletelyUnrelated; };
  33. 33. leaving helpful notesor questions in the code //fred: why set it to 24????
  34. 34. protected member variables for convenience
  35. 35. commenting out code large swathes of it
  36. 36. calling everything foo
  37. 37. @petegoodliffepete@goodliffe.netgoodliffe.blogspot.comwww.goodliffe.net
  38. 38. BUMPH DULL, but important ★THIS DOCUMENT WAS CREATED BY PETE GOODLIFFE IT IS COPYRIGHT // © 2012 PETE GOODLIFFE>> ALL RIGHTS RESERVED>> ALL THOUGHTS ARE OWNED>> PHOTOS AND IMAGES ARE MOSTLY SOURCED FROM THE WEBTHANK YOU FOR READING // I HOPE IT WAS USEFUL Version 1.0 2012-04-25

×