Go and Rust, not Go versus Rust

In the last few months I have been playing around with Rust, Mozilla’s new systems programming language. I worked on small personal projects and submitted a few pull requests (mostly refactoring) to Servo, a Mozilla research project to build a browser engine in Rust.

Another language that often gets mentioned alongside Rust is Go, also known as golang since Go is hard to search for (so is Rust to a lesser extent).

Both languages are compiled, static, strongly typed and have pointers. Both are at a lower level than popular languages like Ruby or Python. They both have been called systems programming languages though this description fits Rust more than it does Go.

I have often seen people asking which one is better or which language should be chosen over the other.

Because of this appearance of opposition and the fact that I already knew Rust, I decided to try Go and see if and how the languages were similar.

Initial impressions of Go

My initial impressions of Go are very good. The language is easy to learn and is nicely designed. If you know any of the following languages; C, C++, Java or C# you’ll be able to jump right in after reading a short tutorial.

The tooling is great, particularly gofmt which formats your code automatically according to the Go style guidelines. I’m using a Vim plugin for Go which calls gofmt each time I save. This process is very nice once you start using it.

One downside is how the package/module/directory structure needs to be set up. It’s not clear when your first start how everything must be structured. It’s important to read this part of the documentation before starting your first project. Otherwise you’ll end up like I did, needing to rearrange the file structure of my git repository because I didn’t follow the proper structure.

Even now that I know the correct file structure I still find it a bit odd and constraining. It’s definitely not one of the language’s strong point.

Comparing Go and Rust

While both languages may seem to serve a similar purpose at first, upon using both they are very different. I have seen many people asking which one is better but the answer depends on what you are building and what you are looking for in a language.

Go is easier to learn. There is deliberately less features in the language and you can hit the ground running after a short tutorial.

Programming is also easier. I spent more time solving problems with my algorithms than I did wrestling with the language.

Go is also garbage collected. That means less to worry about as you don’t have to manage memory. On the other hand, for some applications a garbage collector can be a big downside and it does mean less control.

Rust on the other hand is a more complex language. There is a lot of interesting things in the language and if you’re a language nerd you will love a lot of it’s features. This makes learning and mastering the language harder than Go, but it also makes for a powerful language with a lot of expressive concepts like meta programming through syntax extensions.

I have spent a lot of time battling with the Rust compiler. Compared to Go this means I spend more time solving problems related to the language itself rather than to the algorithms I am writing.

One thing I must say is that when a program finally does compile, there are much less run time errors than in any compiled language I have tried before.

The language isn’t garbage collected and also allows for more control like choosing if memory is allocated on the stack or the heap for example.

Conclusion

Go is a general purpose utilitarian language that’s suitable, amongst other things, for building tools and app back-ends.

Rust is a “PHD smarts” language that’s better suited for systems level stuff and programs where memory management and performance is important.

Go will probably become a go to language when I need a compiled portable low-level language. It’s more modern than C and it’s simpler than C#.

Rust on the other hand is more specialized and is a better choice when doing systems level programs, when garbage collection isn’t an option, or when performance is critical.

Both are wonderful languages and I intend to use them both going forward.

3 thoughts on “Go and Rust, not Go versus Rust

  1. I’m a Go programmer and ended up here searching for info about Rust 🙂
    Just a little comment about something you said that sounded weird: “[Rust] allows for more control like choosing if memory is allocated on the stack or the heap”.
    Go totally lets you put things on the stack and lay out memory however you want. GC doesn’t mean necessarily Java’s crap 😀
    Go also has very good performance, 1.5’s GC runs concurrently with really short stop-the-world pauses. Nothing prevents Go from being almost as fast as C. Just the current compiler isn’t really focused on aggressive optimizations (no loop unrolling, for example).
    I’m going back to my research.
    Cheers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s