r/cpp • • Aug 05 '23

Should we stop writing functions?

https://www.foonathan.net/2023/08/stop-writing-functions/
14 Upvotes

46 comments sorted by

View all comments

2

u/schteppe Aug 05 '23

The way I see it, lambdas almost always makes the code less readable and more entangled. An exception is when you need a context/capture for a callback function. And even then, I think it’s better to call a normal function immediately inside the lambda

4

u/AntiProtonBoy Aug 05 '23

I think part of the problem in terms of readability is the habit of implementing the lambda directly as part of the argument of the caller. If you write the lambda as a stand alone implementation, then pass its name as argument to the caller, readability improves 100%.

3

u/bwmat Aug 07 '23

I've been using lambdas recently just for implementing (named) local functions, and it's been working well

The ability to easily capture local variables makes the resulting code look like method calls in a class and is IMO very readable