In this module we start the course!
Welcome! Welcome to your journey on learning a new programming language -- C++! But if you're reading this, you might not be here just for the language, you are here for the context of learning about pixels. Let me explain. In this text you are going to join me on a journey to learn Modern C++ -- one pixel at a time. Now there are two parts to that last statement, let's take break that down.
You are learning Modern C++ as a modern C++ programmer. Just like the languages we speak go through an evolution, programming languages additionally are constantly evolving. You are not learning 'C with classes', you are not learning the C++ I learned in University C++98, but you are learning a much more rich, modern, and expressive language. While I'm not sure how long we'll call it 'modern c++' that generally refers to the version of the language that is after C++ 11 (11, of course meaning 2011).
Note From all this time forward, when I refer to C++, assume that I mean 'Modern C++'.
The 'one pixel at a time' part of this course means we are primarily going to be building graphical applications as we learn C++. We'll start with a few applications on the console to make sure our systems are setup, as well as cover some foundational material--but soon enough you'll be creating graphical applications. The reason for this, is that I have found it incredibly motivating throughout my career to work on applications where I can 'see visually' the output with my own two eyes.
I believe when learning a new domain (in this case some computer graphics), and a new language (in this case Modern C++), that you should also know a little bit about the history. It will allow you to understand
https://en.wikipedia.org/wiki/Bjarne_Stroustrup
In June of 2020 Bjarne Stroustrup published in the History of Programming Languages a wonderful article talking about the evolution of C++ from 2006 to 2020 -- Thriving in a Croweded World. This article discusses some of the evolution in what is now Modern C++.
Hello world is a classic program used to introduce folks to a programming language. It is seen as a minimally interesting program to test that you are able to program using a specific language with specific tools. So what better place for us to start?
// @file hello.cpp
// g++ hello.cpp -o prog
#include <iostream>
int main(){
std::cout << "Hello World\n";
return 0;
}
Aside, with modern C++ we can put the function return type after main. This is the same program, but some folks prefer this syntax for readability. We'll look at more features and way to write code throughout this adventure.
// @file hello_trailingreturn.cpp
// g++ -g -std=c++11 -o prog
#include <iostream>
auto main() -> int{
std::cout << "Hello World\n";
return 0;
}
As I have mentioned, C++ is an 'evolving language'. At the time of this writing C++ 2023 has another way to output text using the 'print' function which would be familiar to you in many other programming languages (print in Python, println in Java, printf in C, etc.).
// @file hello23.cpp
// g++ -g -std=c++23 -o prog
int main(){
std::print("Hello, World");
return 0;
}
To see if you have a specific feature available, cppreference (a great resource that I'll often reference) that can show you which features are available. As an example, here is the C++ 23 compiler support feature matrix.
The truth is, that in Modern C++ is that we have a lot of different tools. The reality is, we don't have to use them all, and we'll want to slowly build up our knowledge of C++ programming.