How to use correctly the const qualifier?

Sandor Dargo

half-day workshop
beginner
10:30-15:15, Thursday, 1st July 2021

We all use const in our code. But why? Do we use it enough or too much? Do we use it well?

This workshop will provide the answers to those questions! We'll discuss why we need to bring constness to our code and why we need more of it. We'll go into detail to see all the different contexts where const can appear. With the help of examples, we'll examine where it helps, where it's ignored and where it's even harmful!



  • Common arguments against using const

    • const and visual noise
    • const is confusing for the developer
    • It doesn’t matter anyway
  • const local variables

  • const member variables

    • Why would you want to have const members?
    • Some unexpected implications
    • Can we find a workaround?
  • const functions

    • Characteristics of const functions
    • const overloads
  • const return types

    • Returning const objects by value
    • Returning const references
    • Return const pointers
  • const parameters

    • const primitive data types
    • const class type parameters
  • Wrap up

Sandor Dargo

Sandor is a passionate software craftsman focusing on reducing the maintenance costs by developing, applying and enforcing clean code standards. His other core activity is knowledge sharing both oral and written, within and outside of his employer. When not reading or writing, he spends most of his free time with his two children and his wife baking at home or travelling to new places.