6 ms·
C++ has lambdas and local classes. Local classes have some annoying arbitrary limitations, but they are otherwise useful.
by badmintonbaseba 2y ago
C++ has lambdas and local classes. Local classes have some annoying arbitrary limitations, but they are otherwise useful.
- knodi123 2y agoAfter spending a lot of time writing idiomatic React components in es6, I've found my love of locally declared lambdas to really grow. If I give the lambdas really good names, I find that the main body of my component is very, very readable, even more so than if I'd used a more traditional style liberally sprinkled with comments.
- zelphirkalt 2y agoGiving your lambdas names defeats part of their purpose though.
- int_19h 2y agoThey have two distinct purposes: anonymous functions, and closures. Those often go together, but there are many scenarios where you only care about the latter, and don't actually need the former. Named lambdas (i.e. lambdas assigned to local consts) covers this case if the language doesn't have dedicated syntax for it.
- knodi123 2y agomaybe one purpose. but it fulfills another purpose- self-documenting code, and a really simple non-nested main body to your function.
- marcosdumay 2y ago> If I give the lambdas really good names That's a really funny way to say it.