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++

Ólafur Waage

September 13, 2018
Tweet

More Decks by Ólafur Waage

Other Decks in Programming

Transcript

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

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

    a craft • The basics can be explained • But it requires practice
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. A little bit different I want to try a little

    bit of a different approach
  13. 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.
  14. 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.
  15. 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.
  16. Numbers Every single thing in a computer, is represented by

    a number. Everything. Even text. So we will start with focusing on numbers.
  17. 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.
  18. What can we do with a number? The number is

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

    the value of itself. So we can represent the number. 5
  20. 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
  21. 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
  22. 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)
  23. 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?
  24. 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.
  25. 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?
  26. 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?
  27. 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.
  28. 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
  29. 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
  30. 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)
  31. 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.
  32. 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
  33. 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
  34. 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
  35. What numbers? Can we store zero? Yes What is the

    biggest/smallest number we can store? Depends on your computer
  36. 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?
  37. 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?
  38. 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)
  39. 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
  40. Using types Types come before you create any variable, not

    when you use it. Only when you want to make a new variable.
  41. 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
  42. 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.
  43. 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!
  44. 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
  45. 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
  46. Almost a colon In C++ a semicolon is used to

    mark when a statement ends.
  47. 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;
  48. 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.
  49. I have my personal preferences The code I have now

    is great and all. But it’s kinda linear.
  50. 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.
  51. 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?
  52. Conditional statements We can ask questions about the contents of

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

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

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

    variables with an if statement. int numberOfStudents = 11; int numberOfTeachers = 2; if(numberOfStudents > 10) { }
  56. 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; }
  57. 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.
  58. 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
  59. 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;
  60. 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;
  61. 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) { }
  62. 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; }
  63. 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.
  64. Great, now I can make my classroom int numberOfStudentsA =

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

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

    5; int numberOfTeachersA = 2; if(numberOfStudentsA > 10) { numberOfTeachersA = numberOfTeachersA + 1; } int numberOfStudentsB = 11;
  67. 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;
  68. 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) { }
  69. 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; }
  70. This is tedious Problem: Why do I have to keep

    writing the same code again and again for each classroom?
  71. 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.
  72. 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.
  73. 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) { }
  74. 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; }
  75. 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.
  76. It does function So let’s take the logic we had

    before, for the teacher and place it in a function.
  77. 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) { }
  78. 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; }
  79. 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) { } }
  80. 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; } }
  81. 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; }
  82. A bit simpler int GetTeacherCount(int studentCount) { int numberOfTeachers =

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

    2; if(studentCount > 10) { numberOfTeachers = numberOfTeachers + 1; } return numberOfTeachers; } int numberOfStudentsA = 5;
  84. 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);
  85. 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;
  86. 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);
  87. 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?
  88. 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!
  89. Now it’s your turn There are countless locations to learn

    this language https://www.learncpp.com/ https://www.learn-cpp.org/
  90. 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/
  91. 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.
  92. 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/
  93. 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/
  94. 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
  95. 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.
  96. 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
  97. 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
  98. 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
  99. The next steps are up to you It is YOU

    that needs to put in the practice
  100. 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
  101. 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.
  102. 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.