5 ms·
C++ interop sounds like a great unique selling point. Rust/Go/Swift can't match it.
by pornel 7y ago
C++ interop sounds like a great unique selling point. Rust/Go/Swift can't match it.
- k__ 7y agoWhy can't Rust match that?
- efficax 7y agoRust doesn't have classes, for one?
- pornel 7y agoMore 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++.
- k__ 7y agoSeems like Mozilla uses Rust with C++ in Firefox on a daily basis: https://news.ycombinator.com/item?id=21262860 https://news.ycombinator.com/item?id=21262860
- marcosdumay 7y agoMost 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.
- cpeterso 7y agoThe 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. https://github.com/rust-lang/rust-bindgen https://github.com/rust-lang/rust-bindgen
- marcosdumay 7y agoThe 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.
- kungtotte 7y agoIt's not unique. Nim offers C++ interoperability too. https://nim-lang.org/features.html https://nim-lang.org/features.html
- earenndil 7y agoNim does it by compiling to c++, which means it's dependent on c++. D isn't.
- ibobev 7y agoAnd what exactly is the bad thing about that?
- p0nce 7y agocfront, the original C++ compiler, used to compile to C. Why aren't we using such a compiler nowadays?
- he_the_great 7y agoBecause Walter wrote a native compiler. I could see the same fate for nim, Walter writing a native compiler for fun that is.
- zombinedev 7y agoTo escape the shit show that C and C++ are in their unique ways. In my experience, one of the worst things was working on a proprietary 1M+ LoC codebase. Everything was so painful (despite the feats of engineering being put in the internal infra to support the development processes and the great team members I worked with) that I'll never go back to anything like that if I have the choice. I'm also dissatisfied with some of the design decisions accepted into C++11/14/17/20. (Some were fixable and just plainly shortsighted IMO, but others probably not, due to the language legacy). Don't get me wrong, I love learning from the C++ community (conferences, tech talks, blogs and checking out how open-source projects that I'm interested in are implemented), but once that I had tasted the power and freedom of D going back to C++ feels like a huge step in the wrong direction. And also being not only a user, but a contributor is immensely empowering. A PR to the standard library, runtime, compiler or package manager can take anywhere from days to mere hours (depending on the complexity of change), while attempting a change with a similar impact to C++ would likely take anywhere between months to years. And yes, I can see the value of the ISO C++ standardization process, but it's definitely not for me.