| |
| ▲ | fluoridation 5 days ago | parent [-] | | Lambdas are syntactic sugar over functors, and it was possible all along to define a functor that stores a local address and then return it from the scope, thus leaving a dangling pointer. They don't introduce any new places for bugs to creep in, other than confusing programmers who are used to garbage-collected languages. That C++11 is safer than C++98 is still true, as this and other convenience features make it harder to introduce bugs from boilerplate code. | | |
| ▲ | sunshowers 5 days ago | parent [-] | | The ergonomics matter a lot. Of course a lambda is equivalent to a functor that stores a local reference, but making errors with lambdas requires disturbingly little friction. In any case, if you want safety and performance, use Rust. | | |
| ▲ | fluoridation 5 days ago | parent [-] | | >making errors with lambdas requires disturbingly little friction Not any less than other parts of the language. If you capture by reference you need to mind your lifetimes. If you need something more dynamic then capture by copy and use pointers as needed. It unfortunate the developer who introduced that bug you mentioned didn't keep that in mind, but this is not a problem that lambdas introduced; it's been there all along. The exact same thing would've happened if they had stored a reference to a dynamic object in another dynamic object. If the latter lives longer than the former you get a dangling reference. >In any case, if you want safety and performance, use Rust. Personally, I prefer performance and stability. I've already had to fix broken dependencies multiple times after a new rustc version was released. Wake me up when the language is done evolving on a monthly basis. | | |
| ▲ | sunshowers 4 days ago | parent [-] | | So you agree that modern C++ adds new ways to introduce memory unsafety? | | |
| ▲ | fluoridation 4 days ago | parent [-] | | Your question is too broad. I'd have to think about it, but intuitively I'd say no, I don't agree with that. More to the point, lambdas don't introduce any new avenues for memory bugs. Like I said, at the worst they trick inexperienced programmers coming from garbage-collected languages into thinking the platform will deal with lifetimes for them. | | |
| ▲ | sunshowers 4 days ago | parent [-] | | The person who introduced the bug was highly competent and had at least 10 years of C++ experience. He was sure he'd gotten it right and himself didn't believe how subtle the bug turned out to be. The people coming from GC languages have the right expectations about the language taking care of lifetimes for them. I expect nothing less than technical excellence from my tooling. | | |
| ▲ | fluoridation 4 days ago | parent [-] | | To clarify, I'm not interested in debating the skills of any particular programmer. My sole point is that lambdas didn't bring any new ways of mismatching lifetimes. That programmer could have made the exact same mistake with a functor instead and it wouldn't have changed anything. >I expect nothing less than technical excellence from my tooling. Good luck with that. | | |
| ▲ | sunshowers 4 days ago | parent [-] | | I've been having great luck expecting technical excellence from Rust and its community, thank you! |
|
|
|
|
|
|
|
|