Skip to Content
View all events

Safe C++

Published by O'Reilly Media, Inc.

Intermediate content levelIntermediate

Writing safe, simple, and efficient code

Course outcomes

  • Write simpler, safer code
  • Understand the safety-related problems of classic C++
  • Embrace the modern, safer way of writing C++
  • Identify which tools support your development efforts

Course description

The notion that C++ is an unsafe programming language originated with classic C++, i.e., the C++ of the ’90s and 2000s. But C++ has changed fundamentally, and almost all safety-related problems now have wonderfully simple and reliable solutions.

Join expert Klaus Iglberger to discover how you can and should use C++ today to write perfectly safe code. You’ll learn details about typical memory safety issues (initialization, out-of-bounds access, use-after-free, etc.), type safety (conversions, etc.), and undefined behavior. By means of programming examples, you’ll see that modern C++ is not just safe, but also simple and efficient, and you’ll learn how to deal with the “unsafe” parts.

What you’ll learn and how you can apply it

  • Learn to use algorithms instead of for loops
  • Discover how to use strong types to express intent and prevent type conversions
  • Understand how to employ value semantics solutions instead of pointers and references
  • Use constexpr to detect and avoid undefined behavior
  • Learn about tools that help avoid safety-related defects

This live event is for you because...

  • You’re a C++ developer who wants to write safer, simpler, and faster code.
  • You want to see how and why modern C++ is safer by default.
  • You want to understand how to cope with undefined behavior.

Prerequisites

  • One to two years of C++ experience is recommended
  • Attend Essential C++ live courses (recommended, but not required)

Recommended preparation:

  • No preparation required: course material, including slides, code example, and programming tasks will be provided

Recommended follow-up:

Schedule

The time frames are only estimates and may vary according to how the class is progressing.

Module 1 (60 minutes)

  • Presentation and demonstration: Unsafe C++—(non-)initialization of local variables; for/while loops; non-explicit constructors and conversion operators; pointers/references; undefined behavior
  • Demonstration: Code example with multiple occurrences of undefined behavior (UB); introduction of the constexpr keyword; detection of repair of UB with compile time tests
  • Q&A
  • Break

Module 2 (60 minutes)

  • Demonstration: Problems of manual for/while loops; introduction to algorithms; introduction of ranges; replacing for/while loops with algorithms/ranges; implementation of a (generic) strong type; using concepts to avoid bad conversions
  • Presentation: The problems of parameters of fundamental type; the need to express intent in the code; using strong types to avoid many interface-related errors
  • Q&A
  • Break

Module 3 (60 minutes)

  • Demonstration: Strong types in interfaces, continued; using values instead of pointer/references (std::variant, std::function, std::optional)
  • Presentation: The problem of pointers and references
  • Q&A
  • Break

Module 4 (60 minutes)

  • Demonstration: Using values instead of pointer/references, continued
  • Presentation: How to deal with the dangerous features of C++, low-level implementation details, and situations when there is no safe solution; tooling (IDEs, test frameworks, fuzzing frameworks, static code analysis and why not using it is unprofessional, CI/CD environments)
  • Q&A

Your Instructor

  • Klaus Iglberger

    Klaus Iglberger is a freelance C++ trainer and consultant. He is passionate talking about clean, safe and maintainable C++ and shares his expertise in popular C++ courses — from beginner to advanced — all around the world. He is the author of “C++ Software Design”, one of the organizers of the Munich C++ user group, and the (co-)organizer of the Back-to-Basics and Software Design tracks at CppCon.

Skill covered

C++