←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 3 comments | | HN request time: 0s | source
Show context
lordleft ◴[] No.45267931[source]
Great article. Modern C++ has come a really long way. I think lots of people have no idea about the newer features of the standard library and how much they minimize footguns.
replies(2): >>45268114 #>>45268712 #
sunshowers ◴[] No.45268114[source]
Lambdas, a modern C++ feature, can borrow from the stack and escape the stack. (This led to one of the more memorable bugs I've been part of debugging.) It's hard to take any claims about modern C++ seriously when the WG thought this was an acceptable feature to ship.

Of course, the article doesn't mention lambdas.

replies(4): >>45268264 #>>45268485 #>>45268512 #>>45274413 #
1. TuxSH ◴[] No.45268512[source]
Capturing lambdas are no different from handwritten structures with operator() ("functors"), therefore it makes no sense castrating them.

Borrowing from stack is super useful when your lambda also lives in the stack; stack escaping is a problem, but it can be made harder by having templates take Fn& instead of const Fn& or Fn&&; that or just a plain function pointer.

replies(2): >>45268681 #>>45270417 #
2. loeg ◴[] No.45268681[source]
Convenience is a difference in kind.

Like, I'm not god's gift to programming or anything, but I'm decently good at it, and I wrote a use-after-return bug due to a lambda reference last week.

3. sunshowers ◴[] No.45270417[source]
Borrowing from the stack is definitely useful. I do it all the time, safely (truly safely), in Rust.