All posts in "Strong types"

Strong Types for Safe Indexing in Collections – Part 1

Published October 31, 2021 - 0 Comments

Strong types make code safer and more expressive by using the type system to identify individual objects. For example, to instantiate a class Rectangle with a certain width and height, we could write this: Rectangle myRectangle{4, 5}; But then it isn’t clear for a reader of the code which of the two parameters is the […]

Strong Types on Collections

Published July 26, 2019 - 0 Comments

Do we need a special strong type library for collections? Or can we strongly type collections like we do for any object? If you’re joining us right now and haven’t read the previous articles on strong types, long story short, a strong type is a type used instead of another one in order to add […]

How to Be Clear About What Your Functions Return

Published January 23, 2018 - 9 Comments

What’s in a function’s interface? In most languages, a function’s interface has 3 main parts: the function’s name: it indicates what the function does, the function’s parameters: they show what the function takes as input to do its job, the function’s return type: it indicates the output of the function. ReturnType functionName(ParameterType1 parameterName1, ParameterType2 parameterName2); […]

Strong Optionals

Published January 16, 2018 - 5 Comments
Strong optionals

Both strong types and optionals are useful tools to make our interfaces more expressive. Could they be used in synergy to make one benefit from each other? The contents of this post are at an experimental stage. They are laid out here to expose a problem and a possible solution, and as a basis for […]

Strong Templates

Published January 9, 2018 - 9 Comments
Strong templates

Strong typing consists in creating a new type that stands for another type and adds meaning through its name. What would it look like to apply this idea to template interfaces? Disclaimer: What you’ll see in this post is experimental, and it’d be great to have your feedback on it at the end. Strong types for […]

Making Strong Types Implicitly Convertible

Published January 5, 2018 - 0 Comments
Strong types implicit conversions

Strong types and implicit conversions, doesn’t this sound like incompatible features ? It can be argued that they are compatible, in fact. We saw why it could be useful to inherit from the underlying type’s features, and if the underlying type is implicitly convertible to something then you might want to inherit that feature too […]

Using Strong Types to Return Multiple Values

Published November 10, 2017 - 14 Comments

We’ve seen how strong types helped clarifying function interfaces by being explicit about what input parameters the function expected. Now let’s examine how strong types help clarifying functions that return several outputs. We’ll start by describing the various ways to return several outputs from a function in C++, and then see how strong types offer an […]