Recently, I decided to learn Rust programming language and even implement some not too ambitious, but real project in it. I had two reasons for it:
I wanted to have fun. Lua, which I learned to write advanced build systems in tup1 gave me no thrill. It is fine imperative language, but with no inspiring ideas, which I have not already seen in Python.
As I follow, many new vacancies of Tor Project mention Go/Rust requirement.
So, let’s begin. As usual, if you can’t
apt-get it, either it does not exist or does not deserve attention. In case of rust, everything is there: ~~~ # apt-get install rustc cargo rust-doc ~~~
After that, one can browse file:///usr/share/doc/rust-doc/index.html, and start learning either by tutorial, either by series of examples. Standard library reference is also there. Unfortunatelly, documentation is typeset rather poorly; I was forced to use graphical browser.
Rust position itself like very safe C, but with high-level abstractions, like algebraic data types and type inference to make programming comfortable. It feels like C++ done right.
Well, not everything is impeachable. For a language, that claims to be replacement for C, simple “hello world” program, yielding 200Kb binary is, well, much.
After programming Haskell, any other language feels inexpressive, error-prone and repetive. So, if you are okay with huge binaries (tens of megabytes) and garbage collector, just use Haskell.
On other hand, if you are considering C++, or even C, maybe it worth give Rust a shot. Beside smart idea of borrow-checking, Rust has features, that are lacking even in Haskell:
Unit tests can be defined in same module, as main code. Rust build tool,
cargo is smart enough to locate and run them during build, but to exclude them from release binary.
Rust have rather advanced type system, compared to C/C++/Java/etc, and its build tool have separate command to just typecheck code, without generating binary. Just typechecking is fast, and still provides valuable information for development.
Haskell do have this option, but it is buried deep in GHC manual. It is called
-fno-code, which is definitely not as pleasant, as
Cargo builds release and debug versions separately. For compraison, try following with any stack-based Haskell project:
$ stack build $ stack build --fast $ stack build
Last command will re-compile whole project again!