half of the points is completely orthogonal to lambdas. It's like saying that to understand 'int x = 5' you need to understand variadic templates because it might be actually variadic template variable declaration and classes (because it might be not int but class) and const and volatile and multithreading (because you need to understand how to sync it for multithread access), etc
You are talking about the converse of his premise, which doesn't hold; understanding lambdas isn't required to understand any other topic listed. However, understanding lambdas fully, not just being able to use one at a surface level, will give you insight into all of the listed language features. Jason never argues that you must understand those topics to use a lambda in your code. The point is that you could spend a semester just studying the lambda as a topic, investigating how it works under the hood, and walk away with all of those ancillary topics as a side effect. Could you walk away still not knowing any of those topics? Yes, but then you would have failed to understand the lambda on the level being discussed here. Can you learn any other topics from studying int? Well, yes. You can learn how bits are stored and manipulated. You can learn the type system. You can learn about assignment operators. Et cetera. But Lambdas are a seemingly simple thing that touch nearly every core feature of C++ in a meaningful way and is a good tool for learning key concepts.
I discovered your channel recently. It is filling so many holes in my poor knowledge of C++, thanks ! And about this particular one, wow, I feel like I slept during one or two dozen years ! I could explain, but I don't think telling you about my life, the universe and the rest would be interesting !...
@@cppweekly Just done. Now I know that I'm in a deeper sh*t than when writing the previous comment ! If you allow me to brag for few seconds, I would say that while I was implementing requirements, trying to write the most readable and bug free code I could ("ce qui se conçoit bien s'énonce clairement"), some other people were spending all their time changing the language ... OK, I really missed important things though ...
Big missing item: member fields; the captures need to be stored somewhere. Captures are also passed by copy/reference/move, more big concepts important to C++.
Yep. You can have [=] or [&] in the capture to apply to all variables used in the body and scope goes hand in hand with that of course, which is another big aspect of C++ to understand.
Inline functions are also important. The operator() is defined as inline (3:20) this is the cause why no assembly is generated. You also need to understand references and copy-initialization to understand the capture of a lambda. You can also use lambdas for static dispatch; combined with std::integral_constant as a lambda parameter you can enforce the compiler to compile the code as if an integer was constant: // invoke a lambda expression with a given number n, // invoke_n is a template function which calls itself // recursively and tests n against a value in the range // which is given in the template parameter list // if n equals to a number, the lambda function is called // with the parameter n as a std::integral_constant invoke_n( n, [&](N) { // n is an instantiation of std::integral_constant /// use N::value } );
@@connorhorman I mean inline in the sense of not extern, which is also near to static function definitions. Inline is in fact a property of constexpr functions, which is useful and necessary. Some lambda functions can be constexpr as normal functions. Templates declared with the constexpr specifier are sometimes not constexpr if the behavior (which is dependend on the template parameters) is not constexpr.(I do not really know for 100% if this is standard behavior) I think this also exactly applies to lambda functions.
To me it seems easier to learn a new language than understand new (post C++03) C++ rules, so I've learned Python and started to learn Scala and get away from C++. Kinda sad, but I don't have the drive to go into this much detail anymore - well, maybe if some great project came along. Good series though :)
Lambda's are powerful tools but they can obscure the flow especially when callbacks are overused. Microsoft's Chakra engine is full of it and the flow is hard to follow.
Is there some bracket fetish Bjerne has or what? Is there no other possible variety of characters than brackets to use, it isn't as though they aren't already overly over, over used FFS? Also surely this can be done using normal C++ code?...
I now better understand my intuition as to why lambdas should be avoided. They are cryptic and complicate and make code hard to reason about. They discourage code reuse. There are very few use cases where lambda is better than plain old functions/classes/templates.
Wow! my mind is blown away! absolutely amazing! Thank you Jason 😍
Such a meme episode. This channel becames a "Lambdas weekly" slowly but surely
One more thing is "user-defined conversion functions" because lambda with no captures is implicitly convertible to function pointer type
Def I recommend this channel to my fellow colleagues. Thanks Jason
half of the points is completely orthogonal to lambdas. It's like saying that to understand 'int x = 5' you need to understand variadic templates because it might be actually variadic template variable declaration and classes (because it might be not int but class) and const and volatile and multithreading (because you need to understand how to sync it for multithread access), etc
Well put.
And then, scope is missing from that list.
You are talking about the converse of his premise, which doesn't hold; understanding lambdas isn't required to understand any other topic listed. However, understanding lambdas fully, not just being able to use one at a surface level, will give you insight into all of the listed language features. Jason never argues that you must understand those topics to use a lambda in your code. The point is that you could spend a semester just studying the lambda as a topic, investigating how it works under the hood, and walk away with all of those ancillary topics as a side effect. Could you walk away still not knowing any of those topics? Yes, but then you would have failed to understand the lambda on the level being discussed here.
Can you learn any other topics from studying int? Well, yes. You can learn how bits are stored and manipulated. You can learn the type system. You can learn about assignment operators. Et cetera. But Lambdas are a seemingly simple thing that touch nearly every core feature of C++ in a meaningful way and is a good tool for learning key concepts.
I discovered your channel recently. It is filling so many holes in my poor knowledge of C++, thanks !
And about this particular one, wow, I feel like I slept during one or two dozen years ! I could explain, but I don't think telling you about my life, the universe and the rest would be interesting !...
Make sure you check out ua-cam.com/video/VpqwCDSfgz0/v-deo.html too
@@cppweekly Just done. Now I know that I'm in a deeper sh*t than when writing the previous comment !
If you allow me to brag for few seconds, I would say that while I was implementing requirements, trying to write the most readable and bug free code I could ("ce qui se conçoit bien s'énonce clairement"), some other people were spending all their time changing the language ...
OK, I really missed important things though ...
Big missing item: member fields; the captures need to be stored somewhere.
Captures are also passed by copy/reference/move, more big concepts important to C++.
Yep. You can have [=] or [&] in the capture to apply to all variables used in the body and scope goes hand in hand with that of course, which is another big aspect of C++ to understand.
To every thing there is a season,
and a time to every purpose under the heaven:
A time for functors, function pointers, and a time for lambdas.
Thank you Jason Turner
Waiting to see in practice what you mentionned in that list
in the past classes were a sink of features, because that was the most flexible part in cpp, now lambdas...
Thanks Jason! The lambda playlist is a must-watch for me :)
Inline functions are also important. The operator() is defined as inline (3:20) this is the cause why no assembly is generated.
You also need to understand references and copy-initialization to understand the capture of a lambda.
You can also use lambdas for static dispatch; combined with std::integral_constant as a lambda parameter you can enforce the compiler to compile the code as if an integer was constant:
// invoke a lambda expression with a given number n,
// invoke_n is a template function which calls itself
// recursively and tests n against a value in the range
// which is given in the template parameter list
// if n equals to a number, the lambda function is called
// with the parameter n as a std::integral_constant
invoke_n(
n,
[&](N) { // n is an instantiation of std::integral_constant
/// use N::value
}
);
Its constexpr rather than inline as of C++17 if the lambda is defined constexpr or the body meets the requirements of a constexpr function
@@connorhorman otherwise it is defined as inline.
Yeah. Sorry if I didn’t make that implication clear enough.
@@connorhorman I mean inline in the sense of not extern, which is also near to static function definitions. Inline is in fact a property of constexpr functions, which is useful and necessary. Some lambda functions can be constexpr as normal functions. Templates declared with the constexpr specifier are sometimes not constexpr if the behavior (which is dependend on the template parameters) is not constexpr.(I do not really know for 100% if this is standard behavior) I think this also exactly applies to lambda functions.
how to code the nothing :-)
To me it seems easier to learn a new language than understand new (post C++03) C++ rules, so I've learned Python and started to learn Scala and get away from C++. Kinda sad, but I don't have the drive to go into this much detail anymore - well, maybe if some great project came along. Good series though :)
Scala :-). You are going from one beast to another. No complaint about them though, I like both languages.
Very nice talk
Bascilly you need to understand the entire C++ before you understand lambdas
Are there still C++ jobs around? What is the starting salary?
Learn Python and machine learning
Game development
At 2:52 tries to stretch out the video runtime, hiding it with clumsiness. Still missing the 10 minute hurdle :-)
Lambda's are powerful tools but they can obscure the flow especially when callbacks are overused. Microsoft's Chakra engine is full of it and the flow is hard to follow.
That’s why lots of people hate c++ ......
Kind of missed lifetime from that list. Especially important for captured variables.. Unless that was implied by the "objects" point
Is there some bracket fetish Bjerne has or what? Is there no other possible variety of characters than brackets to use, it isn't as though they aren't already overly over, over used FFS? Also surely this can be done using normal C++ code?...
If only...
wtf..this was scary
I now better understand my intuition as to why lambdas should be avoided.
They are cryptic and complicate and make code hard to reason about. They discourage code reuse. There are very few use cases where lambda is better than plain old functions/classes/templates.
Actually, lambdas have turned out to be one of the very best features that was added in C++11.