Advertisement

C++Now 2019: Peter Sommerlad “How I learned to Stop Worrying and Love the C++ Type System”

C++Now 2019: Peter Sommerlad “How I learned to Stop Worrying and Love the C++ Type System”

Presentation Slides, PDFs, Source Code and other presenter materials are available at:

Ward Cunningham's CHECKS pattern language of the 1990s contains the Whole Value Pattern. That pattern claims that using plain value types such as integers, strings or double, especially on a function's interface are not a good practice, because their use is error prone. There are stories about programmers calling a function taking several ints with the wrong sequence of numbers and searching for the bugs. Some claim that named parameters solve those problem, but in my opinion they don't.

C++ has the huge benefit to allow us to define own encapsulated types that are implemented as efficient as the built-in types and that can be clearly distinguished from each other. Unfortunately due to C++'s legacy there are some holes in the type system, like integral promotion and numeric conversions or type aliases, that add to the problem of using plain types for domain values. We should change that practice.

What is a domain value? Even the standard library suffers from using type aliases where a proper domain type would have lessened the issues. The recent discussion of std::span's index type (int or unsigned) shows that. If the standard library would have defined a proper index_type and size_type that are not just integers, that discussion would have been moot and the desired and needed operators for these types could have been defined in a way avoiding the pitfalls of while(v.size()-1 >=0).

This talks demonstrates how to implement and use simple wrapper types and how we could teach that. It also introduces a work-in-progress framework supporting mixing in the minimum set of operators in a type safe way, so that problems of integral promotion or numeric conversion can not happen. Feedback on the latter is appreciated. It deliberately does not attempt to be a full units framework, but to allow distinguish things like width, height and radius from each other and from 42.

Peter Sommerlad
Professor, IFS Institute for Software
Cevelop, Safe C++, CUTE unit testing

Videos Filmed & Edited by Bash Films:

Peter Sommerlad,C++Now 2019,Aspen,Computer Science (Field),+ C (Programming Language),Bash Films,conference video recording services,conference recording services,nationwide conference recording services,conference videography services,conference video recording,conference filming services,conference services,conference recording,conference live streaming,event videographers,capture presentation slides,record presentation slides,event video recording,

Post a Comment

0 Comments