In these uncertain times and multiple months of remote work, at least we have some more time to dive into something new. I have been developing in Go since 2017, learned some TypeScript in the meantime, but few days ago I wanted to get into Rust once again. First time, approximately a year ago I gave up very quickly, realizing that Rust requires lot of time to learn and I didn’t have that much time at the moment.
This time I took a much more serious approach starting reading The Rust Programming Language book, but comparing to the last time, I didn’t stop reading until the last page. I was not familiar with many concepts in Rust, specially traits, “borrowing” and so on, but I immediately realized the power of the expressions in Rust. Both Go and Rust claim to be systems languages, but I have to admit that Rust is much more systems language than Go.
Go is much easier to learn, it reminds of other popular languages and the only difficult part is concurrent programming, specifically taking care of goroutines' lifetime and channel communication.
On the contrary, Rust is much more difficult to learn, has much more concepts and the syntax sometimes looks quite weird (macros, trait bounds, lifetime annotations, closures…). But I didn’t want to stop, I wanted to start a real project and decided to give a try writing a Kubernetes controller. I have some experience writing Kubernetes controllers in Go and anyways I needed a controller that replicates secrets across different namespaces, so this was a very logical choice. The project is named Bond and it is in a very early stage. However, it allowed me to start having feeling of Rust and realizing the power of it’s expression.
What many people say negative about Go are too verbose error handling and lack of generics. Thus, Rust doesn’t have such problems, error handling is really clean and generics concept is very rich. If you don’t already know, Go will probably have generics implementation at the biginning of 2022, but there are no plans of solving the errors problem. Both in Rust and Go, errors are just values, but Rust handles this in quite remarkable way.
Another advantage of Go is quick compiler. Rust takes much more time to compile the code and also linters take more time to analyze it. So, developing in Rust is definitely slower, specially when you are new to the language.
On the other side, Go has memory management based on garbage collector, just like Java for example, and this may introduce some latency in heavy duty applications, which is not the case with Rust. Rust memory management is probably the best and safest ever and takes almost no extra time to handle. Go has goroutines (green threads), while Rust has real OS threads allowing much deeper hardware access, but it also has higher level libraries allowing green threads, async programming using futures, etc.
To summarize, Rust is difficult to learn but if you plan to do real systems programming or develop extremely performant cloud applications, it is the best choice if not even the only good choice at this moment. It is fun to develop APIs in Go, but once it’s not good enough for your use case, definitely give Rust a try, you won’t regret. It is completely worth spending time learning it.