Introduction

I’ve googled in the past about a comparison of Golang vs Rust, but I found few useful answers. In fact, a lot of the posts or threads that I found on the topic mostly said that Golang and Rust are not comparable. And while that may be true on some level, I do think they are comparable in the sense that:

  1. They are both trendy new languages that are gaining a lot of traction.
  2. Also in my experience, the communities have a fair level of overlap e.g. the people who use a lot of Rust are typically pretty familiar with Golang, though I’m not as sure about the inverse.
  3. I’ve even heard of stories of companies such as Discord migrating from Golang to Rust, so that at least suggests that they can be used for similar applications and that there is some level of trade off that can be considered.

And even if they are not similar, I think there is still value in comparing them to see the ways in which they are dissimilar.

Background

I recently saw a talk by Bryan Cantrill talking about the core values of a platform and thought it’d be interesting to approach the comparison from this perspective. In his talk, Bryan says that platforms and technologies tend to have some core values that they revolve around. These core values are important because they are what the people using said technology are typically concerned with, which in turn attracts more people with similar values, creating a feedback loop. This is something that comports with my own personal experience, so I find this is a good basis to compare technologies in general.

The values that he identified are:

  • Approachability
  • Availability
  • Compatibility
  • Composability
  • Debuggability
  • Expressiveness
  • Extensibility
  • Interoperability
  • Integrity
  • Maintainability
  • Measurability
  • Operability
  • Performance
  • Portability
  • Resiliency
  • Rigor
  • Robustness
  • Safety
  • Security
  • Simplicity
  • Stability
  • Thoroughness
  • Transparency
  • Velocity

I will mostly use these same values in my comparison, but with the following changes:

  1. I am grouping Compatibility and Interoperability together because I’m not sure that they are different in the context of programming languages.
  2. I’m removing a few from consideration that I also don’t think apply to programming languages i.e. Availability, Measurability and Resiliency.
  3. I’m removing Thoroughness because I have absolutely no idea what that could mean.
  4. I’m adding Learnability for reasons detailed later in the post. In this context, I’m considering Learnability to be how easy it is to pick up the language if you know some standard programming languages already.

Rust Core Values

My take on Rust’s Core Values

I know that Bryan actually enumerates the values that he sees in Rust later in the talk, but my initial impressions are that the Rust values are:

  • Approachability
  • Composability
  • Expressiveness
  • Extensibility
  • Integrity
  • Performance
  • Rigor
  • Robustness
  • Safety

I put Performance, Rigor, and Safety in bold because I see these as being Rust’s most core values. Traditionally, it was difficult to combine Performance and Safety together. If you wanted to have high performance, you’d traditionally have to use C or C++, but those languages are also famously tricky to use. They rely on the programmer to remember to do things correctly, making them prone to human error – causing bugs such as buffer overflows, dangling pointers or memory leaks. Rust uses Type Theory to empower the type checker to check for correctness to avoid these issues. Your code wouldn’t compile if there were buffer overflows or dangling pointers, and the borrow checker eliminates most common causes for memory leaks. This is just for memory management but using the type checker to avoid human error is prevalent in the Rust culture.

These other values come as a result of this culture. By encoding our problem space into types, we can have the compiler check for completeness and make our programs Robust. The emphasis on Safety and Robustness allows you to compose code without worry. By allowing the type checker and compiler to reduce human error, developers can feel more comfortable using libraries and liberally sharing code. This is in contrast to the C and C++ communities which have a (rightful) tendency to distrust libraries and composing code due to the prevalence of human errors. Over time certain libraries have earned the community’s trust like boost or openssl1, but it’d be wise to be skeptical of a newer library that hasn’t yet reached maturity, which takes a lot of time and can slow down the process of composing code as a community.

Bryan’s take on Rust’s Core Values

Bryan’s values for Rust are:

  • Composability
  • Expressiveness
  • Extensibility
  • Interoperability
  • Integrity
  • Performance
  • Rigor
  • Robustness
  • Safety
  • Security

Initially, it surprised me that he didn’t choose Approachability, but maybe it makes sense because Rust is a pretty dense language to learn. But I do think it’s not fair to the rust community, because my impression is that Approachability is hugely important to the community itself. Additionally, I do find the rust tooling such as cargo to be easy to use and the messages I get from cargo check to be more helpful in comparison to other languages I’ve used, and they hold their developer experience to a high bar. But on the other hand, the language itself is hard to learn especially compared to say Python 2. This is why I made the distinction between Learnability and Approachability earlier.

As for the other differences, Bryan gave Rust Interoperability, which I think is true for Rust but wasn’t necessarily sure it was a core value. Similarly, I didn’t think of Security as a core value so much as a side effect of Rigor being a core value. That being said though, given the second half of Bryan’s definition of core value was how certain technologies attract people interested in particular values, it’s hard to denty that Rust tends to attract people interested in Security and Interoperability, so I will add them to the list as well.

My synthesized take on Rust’s Core Values

  • Approachability
  • Composability
  • Expressiveness
  • Extensibility
  • Compatibility/Interoperability
  • Integrity
  • Performance
  • Rigor
  • Robustness
  • Safety
  • Security

Golang Core Values

I have significantly less experience working with Golang and interacting with the Golang community. As such, the values here are the result of more limited personal experience and research specifically for this post.

That being said, without futher ado, I think the core values of Golang are:

  • Learnability
  • Simplicity
  • Composability
  • Performance
  • Portability
  • Velocity

Golang was extremely easy to be learn and be productive with. This seems to be the experience of everyone who talks about it. I think this is due to the simplicity of the language and the general batteries-included nature of the distribution with the standard library. Golang has few truly unique language constructs, basically just goroutines, channels and the defer keyword. And while I’d argue that you’re really missing out on the Golang experience without using goroutines or channels, these features are opt-in, and you can essentially code without them. Other commonly used language constructs in Golang are also commonly found in comparable languages such as loops, structs, pointers, functions, methods, etc 3. You likely already know how to use some or all of these. Additionally, you don’t need to research libraries to be productive either because like Python, there is a extremely complete standard library that you can use for pretty much any basic use case.

The Golang documentation and blog posts also mention Portability often as a core value. I think they take an interesting approach compared to other languages such as Python, which is traditionally considered to be very portable. Golang is a compiled language that creates a binary that can be used on any machine, while Python can only be used on a machine that also has Python installed. Traditionally, this would come at the cost of scripting, but because of the Velocity core value, Golang compiles quickly and go run certainly feels the same as executing a Python script. Another interesting Porability difference is that Golang binaries tend to not use any dynamic linking, so the resulting binary is much more likely to work out of the box on any machine. Even Python scripts generally require at least glibc, and I’ve personally experienced many times when newer Python scripts would not execute correctly on an older OS.

These all contribute to what I see as Golang’s first and most important priority: Developer productivity. Instead of researching third party libraries, learning abstract language constructs or wrangling your dynamically linked libraries, you spend your time writing code and then copying the binary, you can execute it right away with no worries.

Conclusion

Ultimately Golang and Rust tend to attract people who are interested in new technologies. Many of the popular new tools in the Linux world are written in Rust or Golang these days. To name a few: fzf and docker are written in Golang, and ripgrep and bat are written in Rust. Even the system that keeps this blog running, hugo, is written in Golang.

But on the other hand, they are designed to do different things. And even from the analysis of the values, they tend to be better suited to different kinds of projects, sharing only Composability and Performance. From a technical standpoint it seems like Golang was designed for writing backend web services, and Rust was designed for Systems Programming.

Thanks for reading the article! I hope this article helps readers not only understand the differences between these two programming languages, but also a framework for productively comparing technologies. Even when comparing dissimilar things, we can learn a lot through the process.


  1. Perhaps wrongly earned in the openssl case due to Heartbleed ↩︎

  2. or more aptly Golang ↩︎

  3. With the notable exception of Object Oriented concepts such as inheritance ↩︎