How to use correctly the const qualifier?
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?
- Characteristics of const functions
- const overloads
const return types
- Returning const objects by value
- Returning const references
- Return const pointers
- const primitive data types
- const class type parameters
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.