by RcouF1uZ4gsC · 3y ago · 0 comments
> It is unergonomic to return multiple values by tuple in C++. It can be done, but the calls to std::tie and std::make_tuple are long-winded and distracting, not to mention that you’ll be writing unidiomatically, which is always bad for people who are reading and debugging your code.
C++14 allows you to move capture in lambdas. C++17 has structured bindings that help with returning multiple values.
If you are claiming to an expert in C++ talking about paper cuts, at least be aware of things that have happened in C++ in the last decade.
"Lambda capture" sounds like "my favourite way to juggle chainsaws".
The correct answer to "I don't like lambda syntax..." is not "learn lambda syntax" but "do not use lambdas unless you really need them, and then think twice".
Honestly, C++ is a massive footgun. Write the most simple, inelegant C++ you possibly can. The coming generations who need to maintain your code for the next 200 years will be thankfull for it.
Don't pretend C++ is something more elegant like Ocaml that the compiler sugars you into believing. It's not! It's a horrible pile of ... things ... piled .. on top of .. things .. on top of ...(etc).
And when something goes sideways at any point in that pile of templated tower of abstractions, the compiler will gift you with an outpout that is closer to a mix of toenail clippings and dog poo than an output from an industrial level programming tool. After which you need a heavy drink and wish there was a better language out there. And then you realize there isn't, for the specific task, and you adjust by reducing the complexity of the abstractions you use and prefer to have a codebase that has more lines of code and fever chances of irritating the compiler.
It’s not about the syntax, it’s about understanding the resource management model lambdas add on top of the existing mess.
There is no good reason to use lambdas except parametrization of stl algorithms.
Don’t use them as part of api design. The only thing you gain is one more level of complexity on reasoning resource management.
Yes, to be specific, one should know how they work, and then not use them.
This is in the context of C++ being a minefield of practically infinite complexity, in which the only way to survive is to pick the language subset you know you are able to handle, and stick with it.
Of course, every party picks their own subset :)
IIRC, there are usually several alternate ways to parameterize STL algorithms. If lambdas don't add enough value to be worth the additional complexity in other places, then they don't as STL arguments either.
And I have now addressed structured bindings in the article itself for what they are: a halfway solution, unacceptable to anyone used to real tuples.
Your quote says cpp11 and youre arguing with 14? Wtf?
Source: Someone who was, until recently, limited to C++03. Luckily we're up to 17 now, but occasionally 11 limitations creep in.
In any case, I revised that section to explain how even the "fixed" version in C++14 is still a paper-cut, and make the section hopefully flow a little better.
ETA: I replied to the right comment. I'm agreeing with you :-)