So my current project is to learn Rust. This is part of firm belief that if you don’t actively extend your reach, you’ll be forever stuck in an infinite loop. So Rust it is.
Why Rust? Because the previous time I did something like that I looked at Go, which is nice, but except for green threads (which I’m familiar with from Erlang), it is pretty much the same old thing. I’ll admit that the compilation speeds are pretty attractive there, but I’m working mostly on system software these days, and it seems like it is almost there, but not quite.
So the choice was between Rust and modern C++. The last time I actually did any C++ professionally was in 2006, I needed to build a tool to make a machine join the domain automatically, or something like that. I remember being stuck for an embarrassingly long time on “using std” vs “using namespace std”. Before that, I actually did C++ for a few years, in 1999- 2002 or so. I was below average, at best, but I had read all the Myers books, and I had great confidence that I can mess up real well.
But C++ today is a wildly different beast, much nicer, but at the same time the core concepts (memory management, RAII, etc) I already know, and a lot of the rest seems like stuff that I now take for granted (foreach, auto,lambdas, not doing manual memory management all the time, etc). Looking into modern C++ codebase and discussion, I see a lot of stuff about move constructors and variadic templates. That caused me some pain, but basically, there isn’t anything new there for me, just detail work.
Rust is new, in the sense that it has the Burrow checker and it is supposed to be a safe and fast system programming language. That seems like a big contradiction in term, but it is at least interesting.
So I set out to read the Rust book. I have done so, and below you can see some of my impressions while reading it.
This post is written before I did anything more interesting than writing a hello world.
Rust has macros, and I like that. Should be interesting to see what it can do. Okay, I saw what it can do, and I sort of want to go back to variadic templates. To be rather more exact, that syntax looks sort of the same. And remind me strongly of trying to grok XSLT in the 90s.
I like that it has explicit threading support, and it is interesting that this is baked directly into the language and checked by the compiler. Although some of the stuff that is mentioned there is fishy (Rc<RefCell<Vec<T>>> and other strangeness), but then again, I’ve literally just read the book, so need to see how this work out in practice.
Something that was really strange during the reading is that Rust uses the type of the assignment to infer types.
// parse is generic method, but that implicit type is u32, specified on the assignment
let four: u32 = "4".parse().unwrap();
// this will not compile, not enough type infromation
// this will compile, we are explicit about the type
Speaking of this, I’m used to languages that have far less syntax. In comparison, it seems like Rust have a lot of stuff going on. Most of it seems to be optional/inferred, but that is surprising.
Loop labels and named break/continue are really nice. They are always ugly when you need them.
And obviously, the type system is quite sophisticated. I’m going to see how hard it is going to hurt me when I try writing actually stuff with it.