3 ms·
C++ hides the clones from you for sure, but it means it's a lot easier to figure out in Rust where you're copying the closure (because the copies have to be exp
by eridius 8y ago
C++ hides the clones from you for sure, but it means it's a lot easier to figure out in Rust where you're copying the closure (because the copies have to be explicit) and thus it's easier to reason about the performance of the Rust code.
- masklinn 8y agoThey may also be referring to the more flexible and precise capture clauses of C++ lambdas versus Rust's coarser move v non-move closures. Essentially, capture clauses are a design pattern in Rust whereas they're a language feature in C++: http://smallcultfollowing.com/babysteps/blog/2018/04/24/rust-pattern-precise-closure-capture-clauses/#a-more-general-pattern http://smallcultfollowing.com/babysteps/blog/2018/04/24/rust...
- eridius 8y agoGood point, I was thinking of cloning the closure itself, not capturing Arcs and having to clone them to avoid moves. Though in this case it would be C++'s implicit copies rather than capture clauses. In terms of capture clauses, what I really like are Swift's, as they allow you to bind identifiers to expressions in the capture clause itself (as opposed to just doing capture-by-value vs capture-by-reference). Having capture clauses in Rust that have the same capability would be great.
- pcwalton 8y agoRust used to have capture clauses, but they were removed in order to reduce the complexity of the language. It might make sense to add them back later, but given that Rust is still constantly criticized for being too complex I think it's probably still not yet time.
- masklinn 8y agoThat makes sense to me, I subscribe to the view that software "design patterns" are userland patches for things missing from the language or misuses thereof. The question is then whether the feature is missing enough (the pattern is common) that it makes sense to feed it back into built-in support or not. I don't know how common the knowledge of nikomatsakis's pattern is though, and thus if crates could be automatically searched for it.