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

Language Introduction and Getting Started

Language Introduction and Getting Started

C++ is often thought of as a scary language to start learning. In this meetup of the Malmö C++ User Group we will go over a short introduction of the language and go over many resources on how to get started in the world of C++

89b8f4a7429270308ac301bf7605f974?s=128

Ólafur Waage

September 13, 2018
Tweet

Transcript

  1. None
  2. Language Introduction and Resources to get started

  3. A few things before we get started Software development is

    a craft
  4. A few things before we get started Software development is

    a craft • The basics can be explained
  5. A few things before we get started Software development is

    a craft • The basics can be explained • But it requires practice
  6. A few things before we get started Software development is

    a craft • The basics can be explained • But it requires practice • A lot of practice
  7. A few things before we get started Software development is

    a craft • The basics can be explained • But it requires practice • A lot of practice • For a very long time
  8. http://norvig.com/21-days.html

  9. Define the defines Programming language: “A programming language is a

    vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.” - https://www.webopedia.com/TERM/P/programming_language.html
  10. Define the defines Programming language: “A programming language is a

    vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.” - https://www.webopedia.com/TERM/P/programming_language.html Programming: “The process of writing computer programs.” - https://www.webopedia.com/Programming
  11. Define the defines Programming language: “A programming language is a

    vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.” - https://www.webopedia.com/TERM/P/programming_language.html Programming: “The process of writing computer programs.” - https://www.webopedia.com/Programming Programmer: “The poor soul that has to do all of this work” - me
  12. Highest of levels Sometimes programming languages are called either high

    or low level languages.
  13. Highest of levels Sometimes programming languages are called either high

    or low level languages. I want to call all of them “High Level Languages”, it’s just how high it is, because no language (not even assembly) perfectly describes what is happening on your processor.
  14. Highest of levels Sometimes programming languages are called either high

    or low level languages. I want to call all of them “High Level Languages”, it’s just how high it is, because no language (not even assembly) perfectly describes what is happening on your processor. But that’s just me.
  15. Different approaches There are a few ways to approach learning

    software development.
  16. Different approaches There are a few ways to approach learning

    software development. A very high level approach Just start doing stuff, don’t explain the guts. Similar to learning to drive a car, just press the pedal, don’t explain what is going on.
  17. Different approaches There are a few ways to approach learning

    software development. A very high level approach Just start doing stuff, don’t explain the guts. Similar to learning to drive a car, just press the pedal, don’t explain what is going on. A very low level approach Don’t start programming, explain all the nitty gritty details. Similar to learning math, you learn all these methods and types of mathematics before you can start applying them.
  18. A little bit different I want to try a little

    bit of a different approach
  19. A little bit different I want to try a little

    bit of a different approach A constructivist approach We’re going to “create core C++ language features” as soon as we have a problem that this feature solves.
  20. Features The reason is, all features have a purpose. That

    purpose is to solve a problem.
  21. Features The reason is, all features have a purpose. That

    purpose is to solve a problem. So let’s look at the language and we will ONLY introduce a feature when we stumble upon a problem.
  22. Features The reason is, all features have a purpose. That

    purpose is to solve a problem. So let’s look at the language and we will ONLY introduce a feature when we stumble upon a problem. And since I don’t have that much time, I’m going to focus on the core language.
  23. Let’s go!

  24. Numbers Every single thing in a computer, is represented by

    a number.
  25. Numbers Every single thing in a computer, is represented by

    a number. Everything. Even text. So we will start with focusing on numbers.
  26. Numbers Every single thing in a computer, is represented by

    a number. Everything. Even text. So we will start with focusing on numbers. You might have heard that numbers in computers are stored as binary (0101010) but let’s focus on normal whole numbers. Called integers. No fractions, just simple positive or negative numbers.
  27. What can we do with a number? The number is

    the value of itself. So we can represent the number.
  28. What can we do with a number? The number is

    the value of itself. So we can represent the number. 5
  29. What can we do with a number? The number is

    the value of itself. So we can represent the number. 5 We can add a number with another number
  30. What can we do with a number? The number is

    the value of itself. So we can represent the number. 5 We can add a number with another number 5 + 2
  31. What can we do with a number? The number is

    the value of itself. So we can represent the number. 5 We can add a number with another number 5 + 2 We can subtract, multiply and divide (division will round down)
  32. Ok, but then what? 5 + 2 This is 7

    when the addition is done, but then what, now we’re just left with the number 7. What if I want to add 3 to the number 7?
  33. Ok, but then what? 5 + 2 This is 7

    when the addition is done, but then what, now we’re just left with the number 7. What if I want to add 3 to the number 7? (5 + 2) + 3 Ok, but this can get out of hand quick.
  34. Ok, but then what? 5 + 2 This is 7

    when the addition is done, but then what, now we’re just left with the number 7. What if I want to add 3 to the number 7? (5 + 2) + 3 Ok, but this can get out of hand quick. Problem: What if I want to add some numbers together and then later on add some more numbers?
  35. Memory Computers have memory. And they store numbers in that

    memory. Seems like a perfect fit.
  36. Memory Computers have memory. And they store numbers in that

    memory. Seems like a perfect fit. But how do I put a number into memory?
  37. Variables A variable is a programming language feature focused on

    storing data (numbers) to be used later.
  38. Variables A variable is a programming language feature focused on

    storing data (numbers) to be used later. They need to have a name so you can reference them later. The name is given by you.
  39. Variables A variable is a programming language feature focused on

    storing data (numbers) to be used later. They need to have a name so you can reference them later. The name is given by you. numberOfStudents = 4
  40. Variables A variable is a programming language feature focused on

    storing data (numbers) to be used later. They need to have a name so you can reference them later. The name is given by you. numberOfStudents = 4 numberOfStudents = 5 numberOfStudents = 4 + 2
  41. Variables A variable is a programming language feature focused on

    storing data (numbers) to be used later. They need to have a name so you can reference them later. The name is given by you. numberOfStudents = 4 numberOfStudents = 5 numberOfStudents = 4 + 2 = is not equals but assignment. Think of a variable as a box, you name the box and put stuff in it (a number)
  42. Variables continued numberOfStudents = 5

  43. Variables continued numberOfStudents = 5 numberOfTeachers = 2

  44. Variables continued numberOfStudents = 5 numberOfTeachers = 2 totalClassSize =

    numberOfStudents + numberOfTeachers
  45. Variables continued numberOfStudents = 5 numberOfTeachers = 2 totalClassSize =

    numberOfStudents + numberOfTeachers The calculation on the right hand side of totalClassSize is done first. Think of it like this.
  46. Variables continued numberOfStudents = 5 numberOfTeachers = 2 totalClassSize =

    numberOfStudents + numberOfTeachers The calculation on the right hand side of totalClassSize is done first. Think of it like this. totalClassSize = numberOfStudents + numberOfTeachers
  47. Variables continued numberOfStudents = 5 numberOfTeachers = 2 totalClassSize =

    numberOfStudents + numberOfTeachers The calculation on the right hand side of totalClassSize is done first. Think of it like this. totalClassSize = numberOfStudents + numberOfTeachers totalClassSize = 5 + 2
  48. Variables continued numberOfStudents = 5 numberOfTeachers = 2 totalClassSize =

    numberOfStudents + numberOfTeachers The calculation on the right hand side of totalClassSize is done first. Think of it like this. totalClassSize = numberOfStudents + numberOfTeachers totalClassSize = 5 + 2 totalClassSize = 7
  49. What numbers? Can we store zero? Yes

  50. What numbers? Can we store zero? Yes What is the

    biggest/smallest number we can store? Depends on your computer
  51. What numbers? Can we store zero? Yes What is the

    biggest/smallest number we can store? Depends on your computer What do you mean depends on your computer? Is it 8bit, 16bit, 32bit, 64bit?
  52. What numbers? Can we store zero? Yes What is the

    biggest/smallest number we can store? Depends on your computer What do you mean depends on your computer? Is it 8bit, 16bit, 32bit, 64bit? Problem: What a number is depends on your computer. How can we be more specific so there is no confusion?
  53. Types A type is a way to tell the programming

    language what you are going to put into the variable. (For these cases, we are going to assume you are using a 32 or 64bit computer)
  54. from -2147483648 to 2147483647 from -32768 to 32767 from -128

    to 127 either true or false nothing Types A type is a way to tell the programming language what you are going to put into the variable. (For these cases, we are going to assume you are using a 32 or 64bit computer) int short char bool void
  55. Using types Types come before you create any variable, not

    when you use it. Only when you want to make a new variable.
  56. Using types Types come before you create any variable, not

    when you use it. Only when you want to make a new variable. int numberOfStudents = 5 int numberOfTeachers = 2 int totalClassSize = numberOfStudents + numberOfTeachers
  57. Using types Types come before you create any variable, not

    when you use it. Only when you want to make a new variable. int numberOfStudents = 5 int numberOfTeachers = 2 int totalClassSize = numberOfStudents + numberOfTeachers Now we know what the biggest number we can store, no confusion there.
  58. These are too many lines! I want to be able

    to cram all the code I can into as few lines as I can, so I can read it like a book!
  59. These are too many lines! I want to be able

    to cram all the code I can into as few lines as I can, so I can read it like a book! int numberOfStudents = 5 int numberOfTeachers = 2 int totalClassSize = numberOfStudents + numberOfTeachers
  60. These are too many lines! I want to be able

    to cram all the code I can into as few lines as I can, so I can read it like a book! int numberOfStudents = 5 int numberOfTeachers = 2 int totalClassSize = numberOfStudents + numberOfTeachers Problem: How can the programming language know where one statement ends and another begins
  61. Almost a colon In C++ a semicolon is used to

    mark when a statement ends.
  62. Almost a colon In C++ a semicolon is used to

    mark when a statement ends. int numberOfStudents = 5; int numberOfTeachers = 2; int totalClassSize = numberOfStudents + numberOfTeachers;
  63. Almost a colon In C++ a semicolon is used to

    mark when a statement ends. int numberOfStudents = 5; int numberOfTeachers = 2; int totalClassSize = numberOfStudents + numberOfTeachers; Now you can remove all newlines if you want, but remember, code is for you to read, the computer does not read it like you do.
  64. I have my personal preferences The code I have now

    is great and all. But it’s kinda linear.
  65. I have my personal preferences The code I have now

    is great and all. But it’s kinda linear. I want to add another teacher to the classroom if the number of students is over 10. But there is no way for me to do this with only variables.
  66. I have my personal preferences The code I have now

    is great and all. But it’s kinda linear. I want to add another teacher to the classroom if the number of students is over 10. But there is no way for me to do this with only variables. Problem: How can we run code only if a specific criteria is met?
  67. Conditional statements We can ask questions about the contents of

    variables with an if statement.
  68. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11;
  69. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2;
  70. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2; if(numberOfStudents > 10)
  71. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2; if(numberOfStudents > 10) { }
  72. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2; if(numberOfStudents > 10) { numberOfTeachers = numberOfTeachers + 1; }
  73. Conditional statements We can ask questions about the contents of

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2; if(numberOfStudents > 10) { numberOfTeachers = numberOfTeachers + 1; } If the question inside the ( ) is true, then the statement (or statements) between the { } is executed. Otherwise we skip over it.
  74. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if
  75. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if int sum = 0;
  76. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if int sum = 0; int valueToAdd = 3;
  77. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if int sum = 0; int valueToAdd = 3; while(sum < 10) { }
  78. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if int sum = 0; int valueToAdd = 3; while(sum < 10) { sum = sum + valueToAdd; }
  79. Other conditional statements If you want to keep running the

    statements between the { } until the question becomes false, you can use while instead of if int sum = 0; int valueToAdd = 3; while(sum < 10) { sum = sum + valueToAdd; } When we reach the bottom of the }, we jump back up to the while and ask the question again. Forever, until it is false. Then we jump over it.
  80. Great, now I can make my classroom int numberOfStudentsA =

    5;
  81. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2;
  82. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { }
  83. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; }
  84. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; } int numberOfStudentsB = 11;
  85. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; } int numberOfStudentsB = 11; int numberOfTeachersB = 2;
  86. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; } int numberOfStudentsB = 11; int numberOfTeachersB = 2; if(numberOfStudentsB > 10) { }
  87. Great, now I can make my classroom int numberOfStudentsA =

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; } int numberOfStudentsB = 11; int numberOfTeachersB = 2; if(numberOfStudentsB > 10) { numberOfTeachersB = numberOfTeachersB + 1; }
  88. This is tedious Problem: Why do I have to keep

    writing the same code again and again for each classroom?
  89. This is tedious Problem: Why do I have to keep

    writing the same code again and again for each classroom? I’m going to make a mistake somewhere in this mess, I have 10 classrooms and all sorts of other conditions I have to uphold.
  90. This doesn’t function. A function is a programming language feature

    where you can define a set of statements and wrap them in a nice little package and give it a name.
  91. This doesn’t function. A function is a programming language feature

    where you can define a set of statements and wrap them in a nice little package and give it a name. int add(int numberA, int numberB) { }
  92. This doesn’t function. A function is a programming language feature

    where you can define a set of statements and wrap them in a nice little package and give it a name. int add(int numberA, int numberB) { return numberA + numberB; }
  93. This doesn’t function. A function is a programming language feature

    where you can define a set of statements and wrap them in a nice little package and give it a name. int add(int numberA, int numberB) { return numberA + numberB; } A function can then be used anywhere in the program (after it has been defined) to perform the action and then store it in a variable.
  94. It does function So let’s take the logic we had

    before, for the teacher and place it in a function.
  95. It does function So let’s take the logic we had

    before, for the teacher and place it in a function. int GetTeacherCount(int studentCount) { }
  96. It does function So let’s take the logic we had

    before, for the teacher and place it in a function. int GetTeacherCount(int studentCount) { int numberOfTeachers = 2; }
  97. It does function So let’s take the logic we had

    before, for the teacher and place it in a function. int GetTeacherCount(int studentCount) { int numberOfTeachers = 2; if(studentCount > 10) { } }
  98. It does function So let’s take the logic we had

    before, for the teacher and place it in a function. int GetTeacherCount(int studentCount) { int numberOfTeachers = 2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } }
  99. It does function So let’s take the logic we had

    before, for the teacher and place it in a function. int GetTeacherCount(int studentCount) { int numberOfTeachers = 2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; }
  100. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; }
  101. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; } int numberOfStudentsA = 5;
  102. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; } int numberOfStudentsA = 5; int numberOfTeachersA = GetTeacherCount(numberOfStudentsA);
  103. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; } int numberOfStudentsA = 5; int numberOfTeachersA = GetTeacherCount(numberOfStudentsA); int numberOfStudentsB = 11;
  104. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; } int numberOfStudentsA = 5; int numberOfTeachersA = GetTeacherCount(numberOfStudentsA); int numberOfStudentsB = 11; int numberOfTeachersB = GetTeacherCount(numberOfStudentsB);
  105. There are more problems. Problem: Why do I have to

    always have 2 variables, one for the teacher count and one for the student count, can’t I just group them together somehow?
  106. There are more problems. Problem: Why do I have to

    always have 2 variables, one for the teacher count and one for the student count, can’t I just group them together somehow? Problem: What if I want to have 100 classes, is this then going to turn into a very long file? I don’t want to write all that!
  107. Now it’s your turn There are countless locations to learn

    this language
  108. Now it’s your turn There are countless locations to learn

    this language https://www.learncpp.com/ https://www.learn-cpp.org/
  109. Now it’s your turn There are countless locations to learn

    this language https://www.learncpp.com/ https://www.learn-cpp.org/ https://www.udemy.com/free-learn-c-tutorial-beginners/
  110. Now it’s your turn There are countless locations to learn

    this language https://www.learncpp.com/ https://www.learn-cpp.org/ https://www.udemy.com/free-learn-c-tutorial-beginners/ And not only for C++, many of the concepts we have talked about apply to many other programming languages. The idea is usually the same but it might be written differently.
  111. Tools of the trade So what do I need to

    write code? Well, to get started you need just a computer and internet. There are so many online tools you can use as a way to kickstart your education. http://www.cpp.sh https://www.onlinegdb.com/online_c++_compiler https://wandbox.org/ http://coliru.stacked-crooked.com/
  112. I want bigger and better For windows you have Visual

    Studio: https://visualstudio.microsoft.com/vs/ For mac you have Xcode: https://developer.apple.com/xcode/ And cross platform you have VSCode: https://code.visualstudio.com/ CLion: https://www.jetbrains.com/clion/ Code::Blocks: http://codeblocks.org/
  113. A bolt from god And for those who are a

    little bit further in their journey to learn C++ you have Compiler Explorer: https://godbolt.org
  114. More content There are a lot of C++ conferences around

    the world. Many have wonderful YouTube channels full of lectures, everything from talks like this one to very advanced topics.
  115. Conferences CppCon: https://cppcon.org/ September 23rd in Seattle, Washington

  116. Conferences CppCon: https://cppcon.org/ September 23rd in Seattle, Washington Meeting C++:

    http://meetingcpp.com/ November 15th 2018 in Berlin, DE
  117. Conferences CppCon: https://cppcon.org/ September 23rd in Seattle, Washington Meeting C++:

    http://meetingcpp.com/ November 15th 2018 in Berlin, DE C++ on Sea: https://cpponsea.uk/ February 4th 2019 in Kent, UK
  118. Conferences CppCon: https://cppcon.org/ September 23rd in Seattle, Washington Meeting C++:

    http://meetingcpp.com/ November 15th 2018 in Berlin, DE C++ on Sea: https://cpponsea.uk/ February 4th 2019 in Kent, UK ACCU: https://accu.org April 10th 2019 in Bristol, UK
  119. Conferences CppCon: https://cppcon.org/ September 23rd in Seattle, Washington Meeting C++:

    http://meetingcpp.com/ November 15th 2018 in Berlin, DE C++ on Sea: https://cpponsea.uk/ February 4th 2019 in Kent, UK ACCU: https://accu.org April 10th 2019 in Bristol, UK C++Now: http://cppnow.org/ May 5th 2019 in Aspen, Colorado
  120. The next steps are up to you It is YOU

    that needs to put in the practice
  121. The next steps are up to you It is YOU

    that needs to put in the practice It is YOU that needs to try and most likely struggle trying to find a solution to your problem
  122. The next steps are up to you It is YOU

    that needs to put in the practice It is YOU that needs to try and most likely struggle trying to find a solution to your problem YOU are the driving force here.
  123. The next steps are up to you It is YOU

    that needs to put in the practice It is YOU that needs to try and most likely struggle trying to find a solution to your problem YOU are the driving force here. Programming can be a wonderful craft that empowers you to no end.
  124. Thank you!