3 ms·
I've been programming in C and C++ since sometime around 1992 (and Pascal before that). For the last 3 years, I've been writing Rust professionally. Here's my
by ekidd 8y ago
I've been programming in C and C++ since sometime around 1992 (and Pascal before that). For the last 3 years, I've been writing Rust professionally.
Here's my Rust advice for C and C++ programmers:
- Rust is a higher-level language than C. A C/C++ programmer could think of Rust as "C++ without most of the footguns and magic."
- Certain types of C/C++ code will translate very easily to Rust. For example, if your code mostly transforms bytes (or data structures) into other bytes (or data structures), then Rust will usually be fairly easy to learn. We could call this "mostly functional" C code, with only localized mutability, and with clear, hierarchical data structures. Examples: Most typical Unix CLI tools.
- Certain kinds of C and C++ will translate very badly to Rust. If you have a big web of mutable objects, all of which point to each other and update each other, then your first experience of Rust will probably be frustrating. Examples: doubly-linked lists, traditional GUIs, typical video games. You can do all these things in Rust, but you'll need to either re-architect them or use more advanced features. (See http://cglab.ca/~abeinges/blah/too-many-lists/book/ http://cglab.ca/~abeinges/blah/too-many-lists/book/ for doubly-linked lists, or https://kyren.github.io/2018/09/14/rustconf-talk.html https://kyren.github.io/2018/09/14/rustconf-talk.html for video games.)
- Async Rust is not ready for prime-time. We make limited use of async Rust at work. It's rock-solid and powerful, but it's missing critical ergonomic features and it demands a surprisingly high level of Rust knowledge. See https://areweasyncyet.rs/ https://areweasyncyet.rs/.
Two good Rust books are https://doc.rust-lang.org/stable/book/ https://doc.rust-lang.org/stable/book/ and http://shop.oreilly.com/product/0636920040385.do http://shop.oreilly.com/product/0636920040385.do. "The Rust Programming Language" seems to work best for people coming from Ruby or JavaScript, but I've known several C/C++ programmers who preferred the O'Reilly book.
Honestly, if you're happy with C, there's no reason to switch to Rust. (Except, maybe, preventing exploits, if you worry about that.) If, however, you love certain parts of C++ and hate other parts of C++, then Rust might be worth a look. Anyway, that's my personal take. :-) Overall, I've been really enjoying Rust. It generates fast, reliable code and it fits the way I think.
- curiousDog 8y agoWhat are you building with Rust if you don’t mind sharing? I’m curious to know what sorts of companies are using it out there in production.
- ekidd 8y agoHere are the major categories of stuff we've built in Rust at work: 1. Lots of little CLI tools, statically linked using https://github.com/emk/rust-musl-builder https://github.com/emk/rust-musl-builder. These are fast, portable, easy to share, and easy to add to Docker containers. For a fun open source example, see https://github.com/faradayio/geochunk https://github.com/faradayio/geochunk, which groups US zip codes into evenly-sized chunks. 2. Code where we need to handle all the corner cases very carefully. Rust's enum and match are wonderful for this. An older open source example would be https://github.com/faradayio/cage https://github.com/faradayio/cage, which performed all sorts of fiddly transformations on docker-compose.yml files. (I need to massively overhaul this to work with https://kustomize.io/ https://kustomize.io/ someday.) 3. Code which moves around large amounts of data, and maybe processes some of it. This might involve REST APIs, AMQP queues, cloud buckets or databases. Sometimes we wind up writing a little extra glue code, but we're pretty happy overall. This morning, I'm working on an unreleased open source command-line tool that moves large database tables between different local and cloud databases. This actually uses async Rust (specifically https://tokio.rs/blog/2018-08-async-await/ https://tokio.rs/blog/2018-08-async-await/), which is definitely bleeding edge. But this particular code benefits enormously from Tokio, so we're taking the plunge. Overall, our Rust code is fast and reliable. I enjoy working on it, and my boss likes the fact that our Rust code tends to be very solid.
- deleted 8y ago[deleted]
- js2 8y agoSentry is using it to help their Python backend to process crash reports: https://github.com/getsentry/symbolic https://github.com/getsentry/symbolic
- pimeys 8y agoIn my previous job I wrote a push notification service[0] and a high traffic web server[1] with Rust. Both were rock solid and fast. Now at https://www.prisma.io/ https://www.prisma.io/ we're converting our Scala codebase one module at a time to Rust, plugging them to the Scala codebase with JNA until all the code is converted. Plan is to have better portability between different languages and smaller resource usage. With Rust, interfacing other languages such as Java/Scala, Javascript and so on is quite ergonomic. I also saw Kraken cryptocurrency exchange looking for Rust developers to help with transition, so it seems there is some work opportunities already in the field. [0] https://github.com/xray-tech/xorc-notifications https://github.com/xray-tech/xorc-notifications [1] https://github.com/xray-tech/xorc-gateway https://github.com/xray-tech/xorc-gateway
- markdog12 8y agoI'll probably hold off on learning Rust deeply until they have async/await as keywords. Most of the programming I do involves async, and I currently do my day programming in Dart, which is an absolute joy to do async programming in. They had Future-based APIs from day one, so the whole ecosystem was built around futures starting out. They've had async/await as keywords for over 5 years now. It's so ergonomic it's painful to go back.
- Apocryphon 8y agoInteresting, what kind of job requires you to program in Dart?
- markdog12 8y agoJob didn't "require" it, I was the tech lead of a small startup, and chose Dart for client (WebGL-based game), server side, and supporting command-line tools. It's worked out great and the team loves Dart.