C++: A Wild Ride (2024-09-30 - 2024-10-04)

“New” vs. “Old” C++: An Overview

C++ is a huge pile of language constructs built on top of each other, always backwards compatible with its origins. In 2011, C++ got a major overhaul which is still ongoing. It is not always easy for someone who is new to C++ to understand why things are how they are.

A Live-Hacked Tour Around The New C++ tries to draw the boundary between the old and new C++.

“New” C++: Syntactic Goodies (Pythonicity)

From New Language Features:

Back To The Beginnings Of C++: What Everybody Has To Know

From C To C++

From Data Encapsulation

Classes And Methods (And Functions)

From Functions and Methods

Templates

From C++ Template Basics

Exercises

Inheritance, And Interfaces

From Inheritance And Object Oriented Design

Exercises

  • Refactoring

    • Sensor classes, being-an interface type

    • Funtion average() accepts different kinds of sensors

    • Sensor config, ditto

  • Data logger, initial version.

    Everybody has understood how average() works (using the sensor interface). Write a program that take a sensor configuration, and repeatedly writes measured values to std::cout.

Overengineering (Err, OO Design)

Exercises

What’s bad about logging to std::cout? (Answer: not easily replaced with different logging targets.)

Dependency Injection and Dependency Inversion (and the Strategy Pattern) are different words for one things: software structure.

Idea …

  • Define another interface: logging target (and make std::cout logging its first concrete implementation)

    Discuss MQTT, or SQLite3, …

  • Define a data logger main loop class

More Design Patterns

From Design Patterns With C++:

More C++ >= 11

OO Features

Memory Management

From Smart Pointers (std::unique_ptr, std::shared_ptr):

Exercise

Convert all interface usage to std::shared_ptr<> (Sensor*, LoggingTarget*)

Move Semantics, And Perfect Forwarding

From Move Semantics, Rvalue References:

Same syntax, different meaning …

Exercise

Convert all interface usage to std::unique_ptr<> (Sensor*, LoggingTarget*)

Functional: An Alternative To Full Polymorphism

Going Embedded

Optional Topics