Again, one article just for writing practice. :)
Rust-lang release alpha 1.0 today. Rust aims to be a systems level programming language to replace C and C++. I hit Rust-lang about two month ago, and found it’s a funny language. Then I read some Rust code and also wrote a hobby project with it.
There are several feature attract me:
Write low-level code with safety guarantees
Rust have the concept of onwership. For the resource in computation(this is usually refer to memory, file handler etc), the should be an owner. Rust try to solve the common errors caused by pointers in C/C++, such like dangling pointer, unfree pointer, double free issues. The borrow checker in compiler will keep the resource onwership move correctly with some rules. for more details please refer to offical guide. So as a newbie, writing code in Rust code seems always fighting with compiler. We can not just write code and then fix the memory later, the compiler refuses to accept anything which maybe unsafe, but this also make me think more about the code and design.
By the way, the error hints from compiler is very helpful, this is not like C++(specially templates got in).
There are some comparisons between Go and Rust, Gc is optional in Rust, compare Rust with Go is not sensible.
Recent changes of removing runtime make Rust lower level. There are even some hobby projects writting OS with Rust, refer to this and this.
High level abstraction for system programming
As a modern system programming, Rust is surprisingly expressive. I like the Ruby syntax, Rust has the same similarly mind-blowing effect. Rust carry some functional programming concepts, these make code looks just simple and elegant. Let’s have some trivial code snippet:
Pattern match is so elegant:
Colsures, reminds me with Ruby’s block:
Almost every statement is an expression, this means that the statement returns a value. Blocks are also expression. This is good thing, we may write less “return”! Mixing with pattern match ends with a better sugar.
Of course, nice syntax doesn’t really mean real expresiveness, There are more abstraction tools in Rust, like traits, macro definiation, generic types etc. I have tried some macros for testing in rust-scm.
I have found my favorite interpeter language, it’s Ruby. But in real world, we need to write some code need critical time performance. For this kind of task, Rust maybe a good choice. Benchmarks show Rust is almost as fast as C++.
The Rust have a small, but exciting, openly community. The language have been evolving several years, most design discussion are open source. The core team seems nice.
Have a try for Rust.