Re:My Vision of D’s Future
by k__ on Tuesday October 15, 2019 @11:02AM
(#21259149)
Why can't Rust match that?
[ Parent
| on HN ]
Re:My Vision of D’s Future
by marcosdumay on Tuesday October 15, 2019 @11:18AM
(#21259342)
Most languages settle down with C interop and don't bother with the added complexity from C++. Rust is one of those, some of the concepts aren't even on the language right now, what would lead to very non-idiomatic imports.
The Rust bindgen tool automatically generates Rust FFI bindings to C and C++ libraries. Mozilla uses bindgen a lot to interoperate between Firefox's C++ and Rust code. IIUC, Rust and C++ code can't seamlessly call each other unchanged, but bindgen adds FFI glue that makes it much easier.
Re:My Vision of D’s Future
by marcosdumay on Tuesday October 15, 2019 @05:36PM
(#21264119)
The C++ on the documentation is there for the few places where there's nothing on the interface not supported by Rust. Notice it says it generates biding for "C (and some C++) libraries".
A C interface on C++ code is how most people do interoperability with C++ libraries. It is pretty much C, so you can just use the FFI. But it's not really a C++ compatible FFI.
Rust doesn't have classes, for one?
More specifically, Rust doesn't have inheritance of data. It uses composition and can simulate inheritance of interfaces. That suffices for Rust programs, but gets awkward quickly with some classic OOP-heavy design patterns.
Despite superficially similar angle bracket syntax, C++ templates and Rust generics are very different and incompatible in all but most trivial cases. D templates can get closer.
Rust also lacks many C++-isms: there are no copy/move constructors, no custom code can run on assignment, operator overloading is more conservative, there's no life before main(). Error handling, iterators, and strings are done differently.
Even if C++ could magically work in Rust, it'd be weird. OTOH D feels much like a rewrite of C++.
Seems like Mozilla uses Rust with C++ in Firefox on a daily basis: https://news.ycombinator.com/item?id=21262860