Learning rust and I'm loving it.
I've been coding c++ for about 5+ yrs now, that's how I get most of the work done, plus some python, shell, JS and what not. I started going through the rust book and then the rustlings exercises, which seem quite easy and the behavior of language constructs is very intuitive so far.
Things I've liked so far:
- A+ documentation, amazing really.
- Delivery: I have all the documentation (book + reference + RustByExample) on local storage, so just spin up a python server and its there on any browser on my local network. Having to run this server b/c I have a flatpack mozilla which keeps copying index.html to a temp directory and breaks the experience.
- Content: Again, I'm impressed by the thought put into the documentation, I'll lean more towards RustByExample compared to the Book as it gets to the point quicker most of the times.
- Efforts put into the design. This simplifies code review in a major way. The compiler does half of that really.
- Things like pattern matching and how easily they integrate with errors, optional values, anything with comparison traits I guess (I could be wrong here). Also the syntax sugar "or\_else", "unwrap()", ? etc.
- Modules and visibility. Reference semantics (an unexpected copy doesn't surprise the developer, make extra effort if you want it though)
- Traits (compared to abstract class in cpp). Errors. Lifetime annotations. Inline tests (this is OOTB, no external crate, nothing).
- Cargo. . . I could really write an essay here, maybe it'll be by the time I finish :)
I don't think there's much separating rust and c++ in terms of performance, given the implicit guarantees compiler has when generating code (\\restrict\\, inlining, benefits of static typing etc., hopefully good tagging for branch predictor in matches etc.).
There are couple of places where I think "safe" operations \[ vec.get() for example, or rather full fledged string implementation \] could end up hurting latency rather than throughput. But its just assumptions so far, I'm sure there are other ways of doing these things too.
Now, I've promised myself to test things of my interest with a couple of small projects. Maybe at the same time jumping into a book I have high hopes for (rust for rustlings by Jon Gjengset).
- A custom binary file format with some dictionary compression, I would use bit masks, bitfields etc for (de)serializing something like this in c++ land.
- An expression DAG, I'd use some meta-programming and some runtime graphs, maybe pre-allocated memory for this in c++ land.
C++ has served my purpose well, and tbh I don't face the problems concerning lifetimes and leaks (they are easily avoidable for most use cases). I'd expect it to still be dominant for my work in coming years. But I would really like to use rust for things that are going to be independent of whatever code-base we have so far to this point.
I also rarely write multi-threaded application, though something external will still run them in many threads concurrently.
If you made it to this point, would love to hear any suggestions. . thanks!