Wouldn’t it be great that we could call functions in C++ like this?
It is definitely more readable than what we usually tend to do:
Is there any reason why the first argument should be the width and the second one the height? Not really, and therefore such function call is difficult to read and is error prone. A strong type enforces that the first argument must actually be of type width and the second one of type height so no error would be possible.
In C++ we can actually achieve something like this:
For this example we could be even more precise and do something like this:
The most impressive thing is that in C++ we can achieve this with zero overhead.
Being able to enforce types in our functions and constructor parameters can lead to much readable and less error prone code. In this video we explore the possibilities of a very simple implementation proposed by Jonathan Boccara on this article of his blog.
In the following video we will explain this concept and refactor the constructor for our ftp client library for the Arduino version of the ESP8266.
In the previous article you can find more about the FTP Arduino for ESP8266 client.