Site icon Tomato Soup

Summer Codefest: Lambdas go Baa! [Recap]

#image_title

Webinar overview: 

This presentation by product manager, David Millington, talks about the convenient way to define an anonymous function object added in C++11. This topic was chosen because while it’s extremely useful, the data we see is that there tend to be two groups of C++ developers: those who use them extensively, and those who barely use them.

When to use lambdas:

The main benefits of using lambdas are:

Furthermore, lambdas are especially useful if your logic goes inside something else. These code layering problems are a nuisance to reading code—lambdas make it easier to “localize” logic.

Comparing lambdas with traditional functor

A comparison between a sort functor written in traditional structure vs a lambda.

On the left is a standard functor with structs and operators written traditionally. It works and functions just as a lambda would but it is longer and arguably more difficult to comprehend when viewed in the context of actual source code.

On the other hand, a lambda is seen as significantly shorter and easier to read. With the structure of a lambda, the code being called is emphasized directly after the functions. The syntax is also unmistakable; just look for the following method syntax:

Skip to 18:18 of the replay to learn more about lambda syntax and how to structure inline functions.

Summary: other tips for using lambdas

Here are a couple of other things you should look out for according to the presentation:

Slide Deck Presentation

Replay

Exit mobile version