Arrow of time
Arrow of time

Trying out Nim, D, Go and Rust - part 1

Currently, if I want to describe myself as a developer, I say I'm a "C and Python guy." What ...

Currently, if I want to describe myself as a developer, I say I'm a "C and Python guy." What I mean by that is that I like to work best with C and Python, and seek such opportunities - but it didn't start like that. I basically grew up on BASIC and Pascal and counting by LOC I've probably written the most in PHP. I also have experience with C++, assembly, Java, C# and JavaScript, and whatever else is required in a particular circumstances. While I'll learn whatever, this post is about what I actually enjoy.

So, while I'm very profficient and productive in C and Python, I feel that there's something missing in between the two. In my mind C is

  • low-level
  • powerful
  • needs a lot of boilerplate code
  • fast

and by the same standards, Python is

  • high-level
  • powerful
  • has a large impact / LOC ratio
  • veeeeeryyyy sloooooowwww and crippled by the GIL

There is certainly a lot more which can be said about the two - I'm not trying to be comprehensive. Currently, I'll choose C (or C++) where I think performance will be important, and I'll try to use Python everywhere else. Recently I've come to think that I need a middle ground - a language which I'll like, which would be high-level, AND which must be fast (I'll be happy with getting within 30% of C).

Which got me thinking...

What do I like about a language?

I find C liberating, in the sense that people who practice living self-reliantly and autonomously from the civilization are liberated. It's close to the hardware, and I know I can do anything with it and with any performance goal. At the same time it's a small language, there are not many syntactic forms usable in practice and hardly any exeptions. This smallness is of course in extreme contrast with C++ which has with increasing reliance on templates and metaprogramming (d)evolved to almost nothing but syntax. Together with operator overloading and the recent explosion in pointer types, these features heavily overload the amount of things a programmer needs to keep in his head while working, possibly distracting him from the actual task at hand.

Python has a similarly small syntax, and also one other thing I appreciate: it mostly avoids "sigils". It's a matter of taste, any my tastes go with using words instead of symbols wherever I can. This is one of the reasons why I never bothered to learn Perl, Ruby, and similar languages, and why I actually like writing SQL.

Since I'm moving away from C, this new language needs to be high-level, by which I mean it should have at least the following things:

  • A garbage collector (or similar...)
  • Automatic type inference with static typing
  • Some functional programming features (map, reduce, list comprehensions, ...)
  • Built-in and extensive support for hashes / associative arrays / dictionaries and string manipulation
  • A large standard library with batteries included - think Python-level
  • It must be compiled and the toolchain must generate a proper native executable which are also fast
  • A decent FFI for interfacing with C

Basically, what I'm looking for is a compiled language which "feels" like it's a scripting language in that it has a large impact per LOC (and next to no boilerplate code), which is at the same time fast and powerful.

So in fact, I'd like to try a few recently developed languages and see which one suits me best.

The current offerings

The choice of languages for trying out is somewhat obvious: Nim, D, Go and Rust. The method of testing... certainly isn't. I had big plans - to write 2-3 programs in each of the languages and see from there, but alas, this seems like it will take more time than I currently want to invest in it, so for now, I'll just write a single program in each of the languages, while trying to make it as similar as possible in each implementation.

This program will build a simple Markov chain of the first order from words in a file, and then construct a 100-item sequence of words from the generated table. More specifically, the program will

  • Read lines from stdin
  • Tokenize them with separator characters
  • Build a hash-table keyed by words and containing words following these words
  • Have a function which will generate a sequence of words from this table ("chain") and write them to stdout

I'll write more posts as I go along with the project, saying what I found, what I like and dislike. As a sneak preview, here's the implementation of the test program in Nim :) .

comments powered by Disqus