5 ms·
Let the holy wars begin. "Lambda capture" sounds like "my favourite way to juggle chainsaws". The correct answer to "I don't like lambda syntax..." is not "l
by fsloth 3y ago
Let the holy wars begin.
"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.
- gpderetta 3y agoI don't care if you do not like the lambda syntax (there is plenty of syntax of C++ that I dislike), but lambdas are now a pretty core feature of the language, so you better learn it or switch to another language.
- fsloth 3y agoStrong disagree. 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 :)
- fluoridation 3y agoWould you mind being a little less vague about what's so bad about lambdas?
- fsloth 3y agoLambda-the-cs-concept is ofc beautiful. Lambda-the-c++-language-feature is not. The purpose of programming languages in an industrial context is to make implementations of programs simple. When they utilize complex abstractions, the abstraction should simplify overall architecture. The way to measure the ‘simplification’ is how much reasoning a programmer needs to do to understand what their code does in the context of the language constraints and runtime. In the context of C++ this includes runtime memory use and execution speed. The latter requirement means C++ code must be such that it’s amenable to performance analysis and when hotspots arise, one should have an obvious strategy how to continue. C++ Lambdas make this reasoning more complex (in my experience). So the main problem is the added complexity to reasoning about runtime behaviour, resource use and performance. And this is not complexity that would add value by removing that complexity from some other area of the program. Lambdas in C++ start by looking cute and innocent. Then, when the first problems arise, you realize that by using a lambda instead of just an in-place class to capture the context, which you can reason using the same bysantine set of rules, you actually need to grok a whole new set of rules on top of that: https://en.cppreference.com/w/cpp/language/lambda https://en.cppreference.com/w/cpp/language/lambda That’s a huge mental cost in general what is a saving of few lines of code. Hence, don’t use lambdas in api design. The only way I guess to realize why the lambdas are in such bad taste is to use a programming language where they are part of the core language syntax, like python, scheme, F#… where you can use them without each time double checking that you are not accidentally shooting your foot off.
- gpderetta 3y agoLambdas are just very thin sugar over local classes. I'm not sure what do you find so complex.
- 3y ago