Upgrade to Pro — share decks privately, control downloads, hide ads and more …

We are all C++ teachers

We are all C++ teachers

Explaining an idea is hard. This difficulty grows exponentially the more people you need to talk to. This talk will focus on my journey in learning C++ and then teaching it to others. Touching on things like being a student at University, opening my Twitter DM's to the world, showing common pitfalls in the language and how we can approach others when we want to explain a complex subject.

Ólafur Waage, a native Icelander that has lived in Sweden for the past 4 years. A Senior Programmer at Ubisoft Massive on the Uplay PC Backend Team. Before he was a Developer in the Air Traffic Control industry. Lover of games, music and puzzles.

Ólafur Waage

August 23, 2018
Tweet

More Decks by Ólafur Waage

Other Decks in Programming

Transcript

  1. 1 / 248

  2. Who is "The Icelander" 2 / 248

  3. Who is "The Icelander" Ólafur Waage 3 / 248

  4. Who is "The Icelander" Ólafur Waage Malmö for the last

    4 years 4 / 248
  5. Who is "The Icelander" Ólafur Waage Malmö for the last

    4 years Senior Programmer at Ubiso Massive 5 / 248
  6. Who is "The Icelander" Ólafur Waage Malmö for the last

    4 years Senior Programmer at Ubiso Massive Backend Team on the Uplay PC Project 6 / 248
  7. Who is "The Icelander" Ólafur Waage Malmö for the last

    4 years Senior Programmer at Ubiso Massive Backend Team on the Uplay PC Project Worked in the ATC industry before this 7 / 248
  8. This talk The structure of this talk is 4 stories

    about learning 8 / 248
  9. This talk The structure of this talk is 4 stories

    about learning They're different from another but all focus on learning and teaching in some manner 9 / 248
  10. Let's talk about learning First, some preamble 10 / 248

  11. Let's talk about learning First, some preamble Nobody learns in

    the same manner 11 / 248
  12. Let's talk about learning First, some preamble Nobody learns in

    the same manner This is not a black and white situation, this is a multidimensional problem 12 / 248
  13. Let's talk about learning First, some preamble Nobody learns in

    the same manner This is not a black and white situation, this is a multidimensional problem These kinds of categorizations are contested but they help the points I'm making 13 / 248
  14. Let's talk about learning First, some preamble Nobody learns in

    the same manner This is not a black and white situation, this is a multidimensional problem These kinds of categorizations are contested but they help the points I'm making Many grains of salt 14 / 248
  15. Neil Fleming's VARK model 15 / 248

  16. Neil Fleming's VARK model Visual 16 / 248

  17. Neil Fleming's VARK model Visual Auditory 17 / 248

  18. Neil Fleming's VARK model Visual Auditory Read / Write 18

    / 248
  19. Neil Fleming's VARK model Visual Auditory Read / Write Kinesthetic

    19 / 248
  20. Visual Learner Abstract Images Scribbling figures into a notebook Drawing

    diagrams and how they relate to other diagrams 20 / 248
  21. Auditory Learner Learn by listening Asking questions for clarification Group

    discussions Use of mnemonic devices (Please excuse my dear aunt sally) 21 / 248
  22. Read / Write Writing notes, lots of notes Books, Reports,

    Essays, all great sources of knowledge Translate abstract ideas into text 22 / 248
  23. Kinesthetic Learn by doing Repetition Lots of experiments Change, break

    things, figure out why 23 / 248
  24. #1 Mental Models 24 / 248

  25. Back to school First semester of University, about halfway through

    25 / 248
  26. Back to school First semester of University, about halfway through

    Programming 101 26 / 248
  27. Back to school First semester of University, about halfway through

    Programming 101 We're doing C++ (yay) 27 / 248
  28. Back to school First semester of University, about halfway through

    Programming 101 We're doing C++ (yay) This picture is placed on the projector 28 / 248
  29. 29 / 248

  30. Pointers 30 / 248

  31. Pointers We had a two hour class 31 / 248

  32. Pointers We had a two hour class That was nothing

    but these kinds of pictures with code on the side 32 / 248
  33. Pointers We had a two hour class That was nothing

    but these kinds of pictures with code on the side Stepping through each use case for pointers 33 / 248
  34. Pointers We had a two hour class That was nothing

    but these kinds of pictures with code on the side Stepping through each use case for pointers 195 slides 34 / 248
  35. 35 / 248

  36. Pointers++ Speaker was fine 36 / 248

  37. Pointers++ Speaker was fine Going through the talk now, there's

    nothing wrong in the talk itself (informationally) 37 / 248
  38. Pointers++ Speaker was fine Going through the talk now, there's

    nothing wrong in the talk itself (informationally) But I was completely lost 38 / 248
  39. Pointers++ Speaker was fine Going through the talk now, there's

    nothing wrong in the talk itself (informationally) But I was completely lost I knew what pointers were for 39 / 248
  40. Pointers++ Speaker was fine Going through the talk now, there's

    nothing wrong in the talk itself (informationally) But I was completely lost I knew what pointers were for I knew how to use them 40 / 248
  41. Pointers++ Speaker was fine Going through the talk now, there's

    nothing wrong in the talk itself (informationally) But I was completely lost I knew what pointers were for I knew how to use them This talk was great for Auditory and Visual learners 41 / 248
  42. *Pointers Any pointer exercise made me scared 42 / 248

  43. *Pointers Any pointer exercise made me scared There was always

    this doubt it my mind, that I was missing something 43 / 248
  44. *Pointers Any pointer exercise made me scared There was always

    this doubt it my mind, that I was missing something I knew pointers were in C as well, and back then I had a "very legal" PDF of "The C Programming Language" 44 / 248
  45. *Pointers Any pointer exercise made me scared There was always

    this doubt it my mind, that I was missing something I knew pointers were in C as well, and back then I had a "very legal" PDF of "The C Programming Language" Let's figure this out, what does the book say 45 / 248
  46. *Pointers Any pointer exercise made me scared There was always

    this doubt it my mind, that I was missing something I knew pointers were in C as well, and back then I had a "very legal" PDF of "The C Programming Language" Let's figure this out, what does the book say (PS. These screenshots I got from amazon and similar places giving free samples of the book) 46 / 248
  47. 47 / 248

  48. 48 / 248

  49. 49 / 248

  50. 50 / 248

  51. 51 / 248

  52. *Pointers++ Page 93 ??? Chapter 5 ??? 52 / 248

  53. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? 53 / 248
  54. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? It's 185 pages (a bit more with appendix and a reference manual) 54 / 248
  55. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? It's 185 pages (a bit more with appendix and a reference manual) 50.27% through the book 55 / 248
  56. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? It's 185 pages (a bit more with appendix and a reference manual) 50.27% through the book I went to Page 93 56 / 248
  57. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? It's 185 pages (a bit more with appendix and a reference manual) 50.27% through the book I went to Page 93 I read the first sentence and then I put the book down 57 / 248
  58. *Pointers++ Page 93 ??? Chapter 5 ??? How long is

    this book? It's 185 pages (a bit more with appendix and a reference manual) 50.27% through the book I went to Page 93 I read the first sentence and then I put the book down It was exactly what I was missing. Exactly. 58 / 248
  59. 59 / 248

  60. &Pointers Variables store numbers, this I knew 60 / 248

  61. &Pointers Variables store numbers, this I knew If someone would

    ask me, "what is an address?", I would say "It's just a number" 61 / 248
  62. &Pointers Variables store numbers, this I knew If someone would

    ask me, "what is an address?", I would say "It's just a number" But I never made the connection, because I was fixed on that hammered in box arrow box mental model 62 / 248
  63. &Pointers Variables store numbers, this I knew If someone would

    ask me, "what is an address?", I would say "It's just a number" But I never made the connection, because I was fixed on that hammered in box arrow box mental model It's not magic 63 / 248
  64. 64 / 248

  65. *&Pointers Mental models are very important 65 / 248

  66. *&Pointers Mental models are very important Especially when you are

    starting out learning a topic 66 / 248
  67. *&Pointers Mental models are very important Especially when you are

    starting out learning a topic They can be the springboard you need to learn more 67 / 248
  68. *&Pointers Mental models are very important Especially when you are

    starting out learning a topic They can be the springboard you need to learn more But they can also harm if vital aspects are missing 68 / 248
  69. Quick Example 69 / 248

  70. Quick Example Who here knows what a Monad is? 70

    / 248
  71. Quick Example Who here knows what a Monad is? Monad

    is a monoid in the category of endofunctors, duh! 71 / 248
  72. Quick Example Who here knows what a Monad is? Monad

    is a monoid in the category of endofunctors, duh! This is not helping anyone 72 / 248
  73. Quick Example Who here knows what a Monad is? Monad

    is a monoid in the category of endofunctors, duh! This is not helping anyone ...well maybe some, but not me 73 / 248
  74. Quick Example Who here knows what a Monad is? Monad

    is a monoid in the category of endofunctors, duh! This is not helping anyone ...well maybe some, but not me Here's an example of a mental model. Is it perfect? No. But it helped me get started. 74 / 248
  75. A foot in the door You have a huge library

    of stand alone functions that look something like this 75 / 248
  76. A foot in the door You have a huge library

    of stand alone functions that look something like this ErrorCode IModifyTheIncomingValue( IAmSomeComplexDataType& aCDT) { if(aCDT.WeDoSomeChecks()) { return SomeErrorCode; } // Modify aCDT in some way and return ErrorCode_OK } 76 / 248
  77. Oh no the foot is stuck But it's such a

    hassle to call these functions 77 / 248
  78. Oh no the foot is stuck But it's such a

    hassle to call these functions WhoKnows LetsCallOneOfTheseBadBoys() { IAmSomeComplexDataType cdt; const auto errorCode = IModifyTheIncomingValue(cdt); if(errorCode == SomethingBad) { // there might be many of these if checks return SomeThing; } // Here it's ok to use cdt } 78 / 248
  79. Please help, it's getting numb What if you want to

    chain many of these modifying functions 79 / 248
  80. Please help, it's getting numb What if you want to

    chain many of these modifying functions And only call the next function if the previous one was successful 80 / 248
  81. Please help, it's getting numb What if you want to

    chain many of these modifying functions And only call the next function if the previous one was successful const auto errorCode = IModifyTheIncomingValue(cdt); if(errorCode == SomethingBad) { return SomeThing; } const auto someOtherErrorCode = IAlsoModify(cdt); if(someOtherErrorCode == OhNo) { return SomeOtherThing; } // etc etc 81 / 248
  82. Ahh thanks What if there was a language feature where

    you could chain together modifying functions like that 82 / 248
  83. Ahh thanks What if there was a language feature where

    you could chain together modifying functions like that And the language would do the "exception handling" automatically for you 83 / 248
  84. Ahh thanks What if there was a language feature where

    you could chain together modifying functions like that And the language would do the "exception handling" automatically for you return cdt -> ModifyOne() -> ModifyTwo() -> ICanKeepModifying(); 84 / 248
  85. Ahh thanks What if there was a language feature where

    you could chain together modifying functions like that And the language would do the "exception handling" automatically for you return cdt -> ModifyOne() -> ModifyTwo() -> ICanKeepModifying(); Is this a perfect mental model? No, far from it, the whole field is immense, but it was enough for me to dive deeper 85 / 248
  86. Ahh thanks What if there was a language feature where

    you could chain together modifying functions like that And the language would do the "exception handling" automatically for you return cdt -> ModifyOne() -> ModifyTwo() -> ICanKeepModifying(); Is this a perfect mental model? No, far from it, the whole field is immense, but it was enough for me to dive deeper And mental models should evolve, I'll mention more on that later 86 / 248
  87. #2 You have to start somewhere 87 / 248

  88. Back to the future In November of 2017 I decided

    to open up my Twitter DM's 88 / 248
  89. Back to the future In November of 2017 I decided

    to open up my Twitter DM's The focus was to have a 1 on 1 code review with people new to programming 89 / 248
  90. 90 / 248

  91. Code Reviews - Overview I have done over 50 reviews

    91 / 248
  92. Code Reviews - Overview I have done over 50 reviews

    I have denied about the same amount, because they are not beginners and/or reviewing their code would take hours 92 / 248
  93. Code Reviews - Overview I have done over 50 reviews

    I have denied about the same amount, because they are not beginners and/or reviewing their code would take hours Most contacting me are not asking for code reviews 93 / 248
  94. Code Reviews - Overview I have done over 50 reviews

    I have denied about the same amount, because they are not beginners and/or reviewing their code would take hours Most contacting me are not asking for code reviews But are asking for advice regarding job hunting 94 / 248
  95. Code Reviews - Overview I have done over 50 reviews

    I have denied about the same amount, because they are not beginners and/or reviewing their code would take hours Most contacting me are not asking for code reviews But are asking for advice regarding job hunting Where to learn C++ 95 / 248
  96. Code Reviews - Overview I have done over 50 reviews

    I have denied about the same amount, because they are not beginners and/or reviewing their code would take hours Most contacting me are not asking for code reviews But are asking for advice regarding job hunting Where to learn C++ If their CV is ok 96 / 248
  97. 97 / 248

  98. 98 / 248

  99. 99 / 248

  100. 100 / 248

  101. Code Reviews - The Bad Having an open DM can

    be a negative thing 101 / 248
  102. Code Reviews - The Bad Having an open DM can

    be a negative thing I got sent a lot of graphic photos 102 / 248
  103. Code Reviews - The Bad Having an open DM can

    be a negative thing I got sent a lot of graphic photos I got sent a few shady URL's claiming to be where their code is 103 / 248
  104. Code Reviews - The Bad Having an open DM can

    be a negative thing I got sent a lot of graphic photos I got sent a few shady URL's claiming to be where their code is I was asked once to do a full security audit of a large application and to be marked responsible for it's validity 104 / 248
  105. Code Reviews - The Bad Having an open DM can

    be a negative thing I got sent a lot of graphic photos I got sent a few shady URL's claiming to be where their code is I was asked once to do a full security audit of a large application and to be marked responsible for it's validity But all of these are very much a minority of contacts, but they do happen 105 / 248
  106. Code Reviews - The Good People are so nice and

    respectful 106 / 248
  107. Code Reviews - The Good People are so nice and

    respectful So many are just happy to have someone to chat with about their work 107 / 248
  108. Code Reviews - The Good People are so nice and

    respectful So many are just happy to have someone to chat with about their work I've done a few person to person skype chats with people 108 / 248
  109. Code Reviews - The Good People are so nice and

    respectful So many are just happy to have someone to chat with about their work I've done a few person to person skype chats with people I even did a 2 hour skype session with an Indian University, they were full of questions and so nice. (@NextTechLab) 109 / 248
  110. Code Reviews - The Summary Things have cooled down recently

    110 / 248
  111. Code Reviews - The Summary Things have cooled down recently

    So I took all the code I have reviewed and did a summary of the most common things I point out 111 / 248
  112. Code Reviews - The Summary Things have cooled down recently

    So I took all the code I have reviewed and did a summary of the most common things I point out This is in no particular order 112 / 248
  113. One Function to Rule Them All void IDoEverything_IEvenModifyGlobalState() { //

    Pages of code } 113 / 248
  114. One Function to Rule Them All void IDoEverything_IEvenModifyGlobalState() { //

    Pages of code } It seems that some are taught that they should create functions only when code is reused 114 / 248
  115. One Function to Rule Them All void IDoEverything_IEvenModifyGlobalState() { //

    Pages of code } It seems that some are taught that they should create functions only when code is reused Which tends to turn into the IDoEverything function 115 / 248
  116. One Function to Rule Them All void IDoEverything_IEvenModifyGlobalState() { //

    Pages of code } It seems that some are taught that they should create functions only when code is reused Which tends to turn into the IDoEverything function We generally have a good chat about that creating functions for 1 use is ok 116 / 248
  117. One Function to Rule Them All void IDoEverything_IEvenModifyGlobalState() { //

    Pages of code } It seems that some are taught that they should create functions only when code is reused Which tends to turn into the IDoEverything function We generally have a good chat about that creating functions for 1 use is ok Even similar bits of code can be turned into functions when generalized enough 117 / 248
  118. One Class to Rule Them All class IContainAllTheCode { //

    Visual Studio sometimes crashes when I'm opened } 118 / 248
  119. One Class to Rule Them All class IContainAllTheCode { //

    Visual Studio sometimes crashes when I'm opened } Multiple functions, sure but now we have all the state in one place 119 / 248
  120. One Class to Rule Them All class IContainAllTheCode { //

    Visual Studio sometimes crashes when I'm opened } Multiple functions, sure but now we have all the state in one place I feel this might be insecurity about how to abstract and how to access data from different locations 120 / 248
  121. The Pyramid of Death int AbandonHopeAllYeWhoEnterHere( EnumOfSomeState aWhyAmIBeingPassedIn, std::vector<Thing> aIAmPassedByValue)

    { if(aWhyAmIBeingPassedIn != EnumOfSomeState_Invalid) { if(!aIAmPassedByValue.empty()) { if(aWhyAmIBeingPassedIn == EnumOfSomeState_Small) { for(int i = 0; i < aIAmPassedByValue.size(); ++i) { // trimmed } } } } // More stuff below } 121 / 248
  122. The Pyramid flattened int MoreHopeThisTime( const EnumOfSomeState aIShouldNotChange, const std::vector<Thing>&

    aIAmNotCopied) { if(aIShouldNotChange == EnumOfSomeState_Invalid || aIAmNotCopied.empty()) { return 0; } // etc } 122 / 248
  123. The Pyramid I feel this comes with insecurity with &&

    and || operators 123 / 248
  124. The Pyramid I feel this comes with insecurity with &&

    and || operators The pyramid structure also is more of a natural structure, if you talk about your code 124 / 248
  125. The Pyramid I feel this comes with insecurity with &&

    and || operators The pyramid structure also is more of a natural structure, if you talk about your code "To loop through this list, we can't be in the invalid state, the list can't be empty and we do this loop only if we are in the small state" 125 / 248
  126. The Pyramid I feel this comes with insecurity with &&

    and || operators The pyramid structure also is more of a natural structure, if you talk about your code "To loop through this list, we can't be in the invalid state, the list can't be empty and we do this loop only if we are in the small state" Rater than 126 / 248
  127. The Pyramid I feel this comes with insecurity with &&

    and || operators The pyramid structure also is more of a natural structure, if you talk about your code "To loop through this list, we can't be in the invalid state, the list can't be empty and we do this loop only if we are in the small state" Rater than "If you are invalid or the list is empty, we will exit the function" 127 / 248
  128. Is magic real? int Magic( int aSomeValue, int aSomeOtherValue) {

    if(aSomeValue > 5) // magic number { // stuff } // some other stuff } 128 / 248
  129. WikiWikiWeb Zero One Infinity Rule - "Simply stated: You will

    either need zero of a thing, one of a thing, or an arbitrary number of the thing." http://wiki.c2.com/?ZeroOneInfinityRule 129 / 248
  130. WikiWikiWeb Zero One Infinity Rule - "Simply stated: You will

    either need zero of a thing, one of a thing, or an arbitrary number of the thing." http://wiki.c2.com/?ZeroOneInfinityRule We know that checking against 0 is common place and usually doesn't need context 130 / 248
  131. WikiWikiWeb Zero One Infinity Rule - "Simply stated: You will

    either need zero of a thing, one of a thing, or an arbitrary number of the thing." http://wiki.c2.com/?ZeroOneInfinityRule We know that checking against 0 is common place and usually doesn't need context Similar to 1 and in some cases 2 as well 131 / 248
  132. WikiWikiWeb Zero One Infinity Rule - "Simply stated: You will

    either need zero of a thing, one of a thing, or an arbitrary number of the thing." http://wiki.c2.com/?ZeroOneInfinityRule We know that checking against 0 is common place and usually doesn't need context Similar to 1 and in some cases 2 as well Any other number is magic and needs defined context, or at least a name 132 / 248
  133. WikiWikiWeb Zero One Infinity Rule - "Simply stated: You will

    either need zero of a thing, one of a thing, or an arbitrary number of the thing." http://wiki.c2.com/?ZeroOneInfinityRule We know that checking against 0 is common place and usually doesn't need context Similar to 1 and in some cases 2 as well Any other number is magic and needs defined context, or at least a name Is 5 the number of threads, seconds until next retry or the maximum number of users in a group? 133 / 248
  134. Inconsistent Formatting void imCalledCamelCase() { } void And_Im_Not_Nice_To_Type ( )

    { } 134 / 248
  135. Inconsistent Formatting void imCalledCamelCase() { } void And_Im_Not_Nice_To_Type() { }

    This is a common thing with people who are very new to programming 135 / 248
  136. Inconsistent Formatting void imCalledCamelCase() { } void And_Im_Not_Nice_To_Type( ) {

    } This is a common thing with people who are very new to programming I tell them, what formatting style you use does not matter 136 / 248
  137. Inconsistent Formatting void imCalledCamelCase() { } void And_Im_Not_Nice_To_Type () {

    } This is a common thing with people who are very new to programming I tell them, what formatting style you use does not matter The compiler couldn't care less about how you format 137 / 248
  138. Inconsistent Formatting void im_Called_CamelC_ase() { } void And_Im_Not__Nice_To_Type() { }

    This is a common thing with people who are very new to programming I tell them, what formatting style you use does not matter The compiler couldn't care less about how you format It's going to parse it, errors and all 138 / 248
  139. Inconsistent Formatting void imCalledCamelCase() { } void And_Im_Not_Nice_To_Type ( )

    { } This is a common thing with people who are very new to programming I tell them, what formatting style you use does not matter The compiler couldn't care less about how you format It's going to parse it, errors and all Just be consistent 139 / 248
  140. // This is the title of the slide 140 /

    248
  141. // This is the title of the slide Comments everywhere

    141 / 248
  142. // This is the title of the slide Comments everywhere

    // Here below Olafur will go over the problems of comments // This is the first point 142 / 248
  143. // This is the title of the slide Comments everywhere

    // Here below Olafur will go over the problems of comments // This is the first point So many comments, everywhere, written in all sorts of styles 143 / 248
  144. // This is the title of the slide Comments everywhere

    // Here below Olafur will go over the problems of comments // This is the first point So many comments, everywhere, written in all sorts of styles // Here is the third point 144 / 248
  145. // This is the title of the slide Comments everywhere

    // Here below Olafur will go over the problems of comments // This is the first point So many comments, everywhere, written in all sorts of styles // Here is the third point Comments can be helpful, but what happens is that you double the state of your code 145 / 248
  146. More comments A big problem with comments is that there

    is nothing connecting comments to the code 146 / 248
  147. More comments A big problem with comments is that there

    is nothing connecting comments to the code int ImportantFunction( int aValueOne, int aValueTwo) { // We don't need to check for <some problem> // because that's always done by the caller } 147 / 248
  148. More comments A big problem with comments is that there

    is nothing connecting comments to the code int ImportantFunction( int aValueOne, int aValueTwo) { // We don't need to check for <some problem> // because that's always done by the caller } But what if it's not? 148 / 248
  149. More comments A big problem with comments is that there

    is nothing connecting comments to the code int ImportantFunction( int aValueOne, int aValueTwo) { // We don't need to check for <some problem> // because that's always done by the caller } But what if it's not? A line of comment is as important as a line of code. Review appropriately. 149 / 248
  150. Crowded question Similar problem to one function to rule them

    all, a single if statement packed with checks 150 / 248
  151. Crowded question Similar problem to one function to rule them

    all, a single if statement packed with checks if(myFoo->IsThing(aBar + aBaz->GetStuff(18))) {} 151 / 248
  152. Crowded question Similar problem to one function to rule them

    all, a single if statement packed with checks if(myFoo->IsThing(aBar + aBaz->GetStuff(18))) {} If you're blocking execution with && it is understandable to pack if statements with things 152 / 248
  153. Crowded question Similar problem to one function to rule them

    all, a single if statement packed with checks if(myFoo->IsThing(aBar + aBaz->GetStuff(18))) {} If you're blocking execution with && it is understandable to pack if statements with things But for readability and maintainability, things like this are a strain to anyone who comes across it 153 / 248
  154. "Stringly typed" if(userType == "AdminUser") { } 154 / 248

  155. "Stringly typed" if(userType == "AdminUser") { } Avoid depending on

    information stored in a string 155 / 248
  156. "Stringly typed" if(userType == "AdminUser") { } Avoid depending on

    information stored in a string Unless you are doing actual string parsing or converting from a string source to a typed result 156 / 248
  157. "Stringly typed" if(userType == "AdminUser") { } Avoid depending on

    information stored in a string Unless you are doing actual string parsing or converting from a string source to a typed result Use Types, Classes, Enums, even integers 157 / 248
  158. "Stringly typed" if(userType == "AdminUser") { } Avoid depending on

    information stored in a string Unless you are doing actual string parsing or converting from a string source to a typed result Use Types, Classes, Enums, even integers Stringly typed is a very common way of turning a compile time error into a runtime crash 158 / 248
  159. Review of Reviews These mistakes have a common theme 159

    / 248
  160. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice 160 / 248
  161. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice "Well duh" ... but ... 161 / 248
  162. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice "Well duh" ... but ... I've seen these kinds of mistakes in code written by 10 year veterans 162 / 248
  163. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice "Well duh" ... but ... I've seen these kinds of mistakes in code written by 10 year veterans Not as obvious though, but more nuanced 163 / 248
  164. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice "Well duh" ... but ... I've seen these kinds of mistakes in code written by 10 year veterans Not as obvious though, but more nuanced We found and fixed a crash in Uplay that was "Stringly typed" in disguise 164 / 248
  165. Review of Reviews These mistakes have a common theme Lack

    of Experience and Practice "Well duh" ... but ... I've seen these kinds of mistakes in code written by 10 year veterans Not as obvious though, but more nuanced We found and fixed a crash in Uplay that was "Stringly typed" in disguise I've seen a gigantic function in live ATC code because splitting it up was "Harder to prove correct" 165 / 248
  166. #3 Invisible Problems 166 / 248

  167. On the job Let's imagine being a C++ programmer 167

    / 248
  168. On the job Let's imagine being a C++ programmer We

    are ok with the language but not super secure 168 / 248
  169. On the job Let's imagine being a C++ programmer We

    are ok with the language but not super secure We are tasked with upgrading a part of an older system 169 / 248
  170. On the job Let's imagine being a C++ programmer We

    are ok with the language but not super secure We are tasked with upgrading a part of an older system And in the section we are now, the best solution is a struct with two integers 170 / 248
  171. Lets do this struct VeryImportant { }; 171 / 248

  172. The two ints struct VeryImportant { int myOne; int myTwo;

    }; 172 / 248
  173. So far, so good Then someone tells us 173 /

    248
  174. So far, so good Then someone tells us "Please make

    sure everything is correctly initialized, we can't have junk values here!" 174 / 248
  175. Zero is default? Right? struct VeryImportant { int myOne; int

    myTwo; VeryImportant(): myOne(0), myTwo(0) {} }; 175 / 248
  176. One step at at time Then someone tells us 176

    / 248
  177. One step at at time Then someone tells us "I

    want to be able to set the values when I create the object" 177 / 248
  178. We got this! struct VeryImportant { int myOne; int myTwo;

    VeryImportant(): myOne(0), myTwo(0) {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} }; 178 / 248
  179. Oh no... Then someone tells us 179 / 248

  180. Oh no... Then someone tells us "This object has to

    be correct when it's copied, can you do that?" 180 / 248
  181. The rule of how many? struct VeryImportant { int myOne;

    int myTwo; VeryImportant(): myOne(0), myTwo(0) {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} VeryImportant(const VeryImportant& aVery) : myOne(aVery.myOne), myTwo(aVery.myTwo) {} VeryImportant& operator=(const VeryImportant& aVery) { myOne = aVery.myOne; myTwo = aVery.myTwo; return *this; } }; 181 / 248
  182. Who is this person? Then someone tells us 182 /

    248
  183. Who is this person? Then someone tells us "We upgraded

    to the new compiler, it supports move semantics, can you make sure everything is movable?" 183 / 248
  184. struct VeryImportant { int myOne; int myTwo; VeryImportant(): myOne(0), myTwo(0)

    {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} VeryImportant(const VeryImportant& aVery) : myOne(aVery.myOne), myTwo(aVery.myTwo) {} VeryImportant& operator=(const VeryImportant& aVery) { myOne = aVery.myOne; myTwo = aVery.myTwo; return *this; } VeryImportant(VeryImportant&& aVery) : myOne(aVery.myOne), myTwo(aVery.myTwo) {} VeryImportant& operator=(VeryImportant&& aVery) { myOne = aVery.myOne; myTwo = aVery.myTwo; return *this; } }; 184 / 248
  185. What have you done? Then we get a call 185

    / 248
  186. What have you done? Then we get a call "Why

    is our new VeryImportant struct slower than our old library?" 186 / 248
  187. Searching starts 187 / 248

  188. Searching starts You look over your code, nothing 188 /

    248
  189. Searching starts You look over your code, nothing You look

    at all the call sites, nothing 189 / 248
  190. Searching starts You look over your code, nothing You look

    at all the call sites, nothing You start doing git blame diffs, nothing 190 / 248
  191. Searching starts You look over your code, nothing You look

    at all the call sites, nothing You start doing git blame diffs, nothing You go into assembly... 191 / 248
  192. 192 / 248

  193. "Why is my code slow" 193 / 248

  194. "Why is my code slow" You start googling something like

    that 194 / 248
  195. "Why is my code slow" You start googling something like

    that Sprinkle in memcpy and structs 195 / 248
  196. "Why is my code slow" You start googling something like

    that Sprinkle in memcpy and structs A certain word keeps popping up 196 / 248
  197. "Why is my code slow" You start googling something like

    that Sprinkle in memcpy and structs A certain word keeps popping up Trivial 197 / 248
  198. "Objects of trivially-copyable types are the only C++ objects that

    may be safely copied with std::memcpy" 198 / 248
  199. 199 / 248

  200. struct VeryImportant { int myOne; int myTwo; VeryImportant(): myOne(0), myTwo(0)

    {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} VeryImportant(const VeryImportant& aVery) : myOne(aVery.myOne), myTwo(aVery.myTwo) {} VeryImportant& operator=(const VeryImportant& aVery) { myOne = aVery.myOne; myTwo = aVery.myTwo; return *this; } VeryImportant(VeryImportant&& aVery) : myOne(aVery.myOne), myTwo(aVery.myTwo) {} VeryImportant& operator=(VeryImportant&& aVery) { myOne = aVery.myOne; myTwo = aVery.myTwo; return *this; } }; 200 / 248
  201. So what am I allowed to do? 201 / 248

  202. So what am I allowed to do? What is 'Trivial'?

    202 / 248
  203. So what am I allowed to do? What is 'Trivial'?

    A trivial copy constructor is one not made by the user 203 / 248
  204. So what am I allowed to do? What is 'Trivial'?

    A trivial copy constructor is one not made by the user A trivial move constructor is one not made by the user 204 / 248
  205. So what am I allowed to do? What is 'Trivial'?

    A trivial copy constructor is one not made by the user A trivial move constructor is one not made by the user A trivial copy assignment operator is one not made by the user 205 / 248
  206. So what am I allowed to do? What is 'Trivial'?

    A trivial copy constructor is one not made by the user A trivial move constructor is one not made by the user A trivial copy assignment operator is one not made by the user A trivial move assignment operator is one not made by the user 206 / 248
  207. We're back here struct VeryImportant { int myOne; int myTwo;

    VeryImportant(): myOne(0), myTwo(0) {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} }; 207 / 248
  208. 208 / 248

  209. But there is a catch There is a thing called

    std::is_trivial 209 / 248
  210. But there is a catch There is a thing called

    std::is_trivial I thought at first that was the one to use 210 / 248
  211. But there is a catch There is a thing called

    std::is_trivial I thought at first that was the one to use std::is_trivial is 211 / 248
  212. But there is a catch There is a thing called

    std::is_trivial I thought at first that was the one to use std::is_trivial is std::is_trivially_copyable 212 / 248
  213. But there is a catch There is a thing called

    std::is_trivial I thought at first that was the one to use std::is_trivial is std::is_trivially_copyable AND std::is_trivially_default_constructible 213 / 248
  214. is_trivially_default_constructible 214 / 248

  215. is_trivially_default_constructible Quite the beast 215 / 248

  216. is_trivially_default_constructible Quite the beast You are not allowed to default

    initialize anything 216 / 248
  217. is_trivially_default_constructible Quite the beast You are not allowed to default

    initialize anything Anything 217 / 248
  218. Not Allowed struct VeryImportant { int myOne; int myTwo; VeryImportant():

    myOne(0), myTwo(0) {} }; 218 / 248
  219. Also a big no no struct VeryImportant { int myOne

    = 0; int myTwo = 0; }; 219 / 248
  220. is_trivially_default_constructible: 2 And to what benefit? 220 / 248

  221. is_trivially_default_constructible: 2 And to what benefit? Not sure, some talks

    about what type is allowed in a constexpr context 221 / 248
  222. The only healthy choice #define ENFORCE_TRIVIAL(t) \ static_assert(std::is_trivially_copyable_v<t>); \ static_assert(std::is_trivially_copy_assignable_v<t>);

    \ static_assert(std::is_trivially_copy_constructible_v<t>); \ static_assert(std::is_trivially_move_assignable_v<t>); \ static_assert(std::is_trivially_move_constructible_v<t>); \ static_assert(std::is_trivially_destructible_v<t>); #define TRIVIAL_STRUCT(name, ...) \ struct name __VA_ARGS__; \ ENFORCE_TRIVIAL(name); TRIVIAL_STRUCT(VeryImportant, { int myOne; int myTwo; VeryImportant(): myOne(0), myTwo(0) {} VeryImportant(int aOne, int aTwo): myOne(aOne), myTwo(aTwo) {} }); 222 / 248
  223. #4 Old Mental Models 223 / 248

  224. Copy elision, RVO, NRVO, oh my 224 / 248

  225. Copy elision, RVO, NRVO, oh my What does NRVO stand

    for? 225 / 248
  226. Copy elision, RVO, NRVO, oh my What does NRVO stand

    for? Ok, what are we optimizing? 226 / 248
  227. Copy elision, RVO, NRVO, oh my What does NRVO stand

    for? Ok, what are we optimizing? Is copy elision ever guaranteed? 227 / 248
  228. Copy elision, RVO, NRVO, oh my What does NRVO stand

    for? Ok, what are we optimizing? Is copy elision ever guaranteed? What about constexpr? 228 / 248
  229. 229 / 248

  230. 230 / 248

  231. Understanding the RVO family 231 / 248

  232. Understanding the RVO family For me, I understood them fine

    232 / 248
  233. Understanding the RVO family For me, I understood them fine

    But I never knew when they would be applied 233 / 248
  234. Understanding the RVO family For me, I understood them fine

    But I never knew when they would be applied Again, I had this insecurity, "Was this an RVO or not?" 234 / 248
  235. Understanding the RVO family For me, I understood them fine

    But I never knew when they would be applied Again, I had this insecurity, "Was this an RVO or not?" Until I saw Jon Kalb's lightning talk on Copy Elision 235 / 248
  236. 236 / 248

  237. Call To Action 237 / 248

  238. Call To Action I'm not going to spoil his talk

    238 / 248
  239. Call To Action I'm not going to spoil his talk

    This is your homework, it might force you to think about the RVO family in a different way 239 / 248
  240. So now what? We all learn differently 240 / 248

  241. So now what? We all learn differently We all teach

    differently 241 / 248
  242. So now what? We all learn differently We all teach

    differently Even chatting with co-workers, we are teaching in some sense 242 / 248
  243. So now what? We all learn differently We all teach

    differently Even chatting with co-workers, we are teaching in some sense So when something seems confusing to someone else 243 / 248
  244. So now what? We all learn differently We all teach

    differently Even chatting with co-workers, we are teaching in some sense So when something seems confusing to someone else Try explaining it in a completely different manner 244 / 248
  245. So now what? We all learn differently We all teach

    differently Even chatting with co-workers, we are teaching in some sense So when something seems confusing to someone else Try explaining it in a completely different manner You might learn something about it yourself 245 / 248
  246. Very Holistic "What really is the point of trying to

    teach anything to anybody?" 246 / 248
  247. Very Holistic "What really is the point of trying to

    teach anything to anybody?" "What I mean is that if you really want to understand something, the best way is to try and explain it to someone else. That forces you to sort it out in your mind. And the more slow and dim-witted your pupil, the more you have to break things down into more and more simple ideas. And that's really the essence of programming. By the time you've sorted out a complicated idea into little steps that even a stupid machine can deal with, you've learned something about it yourself." - Douglas Adams 247 / 248
  248. Never stop learning, never stop teaching 248 / 248