Hacker News new | past | comments | ask | show | jobs | submit login

Lambda functions are just syntax, they aren't "flexible" in any meaningful way I can see. And I argue that they certainly are rare -- virtually all major languages (other than C and C++03) have some form of straightforward anonymous function with some form of local scope closure (and to be clear: C++11's implementation of that bit is sort of a mess!).

Other than node.js, virtually none of them make regular use of them. When they do, it's mostly just to have a convenient way of passing a callback.

Lambda's are good. But as implemented in C++11 they really don't do anything to change the nature of the code being written. On the other hand, proper use of initializers does, by virtue of not having to write a thousand setXXX() functions, etc...




"Lambda functions are just syntax, they aren't "flexible" in any meaningful way I can see"

I disagree with that statement. To the best of my knowledge, lambdas functions are implemented as functors which are created by the compiler. So to have a comparable code you have to create those functors by hand. Which can be a lot of repetitive and boring work if you are doing something like an event system.

"virtually all major languages (other than C and C++03) have some form of straightforward anonymous function"

What about Java? :)

"virtually none of them make regular use of them. When they do, it's mostly just to have a convenient way of passing a callback."

Coming from Scheme (which yeah we can argue whether is a major language or not) I can see a lot of benefits of using closures, way more than just a convenient way to pass a callback.

"Lambda's are good. But as implemented in C++11 they really don't do anything to change the nature of the code being written."

Even when is not as powerful as the implementation in other languages still is a huge gain rather not having them at all. If you use them accordingly you would found a more concise and clear code in comparison with not using them. At least that was my personal experience.


For me, the lack of lamba functions meant I was less likely to use many of the algorithms from the standard library. In general, you want to provide a functor to such functions, and it doesn't make sense to define a class, overload operator(), and get the member variables and instantiations to line up when you could just write a for loop. With lambdas, the compiler will do that boiler plate for me.

(Yes, I say "will" - I'm not yet working on something that lets me use C++11 features. Sigh.)


This is what a like about C++11, it feels a safer language and lets me do lots of functional style programming.

Sadly I am stuck in JVM/.NET on the day job.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: