I was not aware that they’d made that optimisation. That’s pretty useful.
I suspect C# does something similar,
but I’m not sure what I’d have to search to find out whether it does or not.
(Eric Lippert’s probably mentioned it somewhere on his blog.)
This is one of the places where C++ excels.
A lot of people give C++ flak for using the
<< operator to do stream output, but…
I once wrote something like this for Arduboy:
Print & operator <<(Print & printer, const T & object)
Which means that something like
arduboy << F("Distance: ") << mDistance << 'm'; ends up being (roughly) equivalent to
(We could easily add something like this to the PokittoLib if there was interest in doing so.)
Sadly Java can’t do this because there’s no operator overloading.
The closest it can get is method chaining.
Personally I’ve never been a fan of method chaining where the method returns
this, to me it’s always felt like it’s compensating for a lack of better features.
What about making local variables
Does that also have the same optimisation?