thejeeb
15
Thanks @tylerweaver. I was going to reply with pretty much a similar set of features but you did a much better job than me.
I wanted to point an example of a minor C++20 feature that came up recently. A developer recently wanted to use map.contains(key) and I said it was only available in C++20. So the developer was resigned to using map.find(key) != map.end() or map.count(key) > 0, both of which are are poor substitutions for existence of a key in a map. My point here is not that this is a reason to move to C++20. It is that one of the goals of the evolution of C++ by the standards body is to make the language easier to use and understand. My example is admittedly a poor example but I can point to extremely complex written C++ code that can replicated in much simpler understandable syntax in languages like C# or Python, for example. And no, this is not a “code prettifying hack”. It is code that I write that I want myself and other developers to clearly understand the intention of the code a year or two from now, without having to “decipher” the meaning of the code. It leads to better code maintenance. The standards committee are continually introducing features that help make our code more expressive and intentional without sacrificing the performance guarantees of C++. This includes new language features, code semantics and new library features all of which are intended to improve the use and understandability of your code.
One more thing, maybe minor. If you want new developers joining the ros 2 ecosystem, then you most likely want to keep updating the ecosystem to the latest language features. Users are less likely to join the ros 2 ecosystem, if it is still stuck on C++14 and they have been using C++26 in their previous job.
I’m not minimizing the effort it takes to qualify the ros 2 core packages with C++20 - I’m sure that is a significant effort. But as an end user developing a ros 2 application, the fact that the latest ros 2 distro has made C++20 the default C++ version does not in any way mandate you to use C++20 in your own code. A developer is free to write his/her application using the constructs of any earlier version of C++ including C++98 if you so choose. That is the backwards compatibility guarantee of successive version of C++. The only time they have deprecated and removed features is when they are broken e.g. auto_ptr. You should be able to recompile your C++11 code and keep chugging along without using any of the newer language features. I have even found bugs in my existing application code when compiling with a newer compiler e.g. when there is stricter checking.
At some point, you have to move forward with the language so developers who want to use it can. The only question is when. You can make the same argument why we need to keep adding features to the ros 2 core and just stick with ‘foxy’ and just only fix bugs. The ros 2 distro upgrades are even worse since they break both source and binary compatibility. But that is acceptable to gain the new features.
3 Likes