CPP as a second language

Where does C++ fit in?

Overview

Teaching: 8 min
Exercises: 0 min
Questions
  • How does C++ compare to other languages?

  • What is C++ used for?

  • When should I use C++?

  • What is C++’s relationship to C?

Objectives
  • Understand C++ role in programming

C/C++ as compared to other languages

What is C/C++ used for?

C++ is used for lots of things, which is why it has a much larger user community than say Fortran for example.

When should I use C++?

If a program you are working on already uses C++, or uses C++ to write extensions. In new programs, if you aren’t writing highly performance critical programs, something like Python might be a better choice. It is easy to use and you can write your programs much faster. When you find slow parts of your code use libraries that can do those parts faster, e.g. numpy. If there isn’t a library for it, use Cython to generate C/C++ code from your python by adding type information to your variables. See our parallel computing summer school materials on using Cython for more information about how to get started using Cython. While converting your Python code to Cython it can be useful to know some C/C++ and can give you more flexibility in how you do it, for example you could write your performance critical bits directly using C++ as python modules.

What does C++ add to C?

Three main components added:

There are certainly many other bits that C++ adds, but these are the conceptually most important additions.

C and C++ interoperability

Versions of C++ and its Complexity

Versions: C++98, C++03, C++11, C++14, C++17, C++20, C++23

Lots of additional components added in each iteration. The C++ language is vast and complex (one of the main criticisms of the language) and it is not feasible to cover all the different ways things can be done and all the features from all the versions in just 4 hrs. However, we will cover the core concepts and language components and features that are present through many of the versions of C++ with the hope that this will provide a sufficient foundation to allow learning additional features and components of the language as needed.

Indeed many professional developers who use C++ restrict themselves to a subset of features to reduce the complexity of code and allow more people to understand and use it. I would highly recommend this approach to help keep yourself sane.

Key Points