Starting in Rust, Coming From Go
Tags: Rust, Go, Learning And Development

Photo by Nick Fewings on Unsplash

I’ve worked in a lot of languages and am always interested in picking up new ones. I’d wanted to try Rust but just hadn’t made time. Reading that Rust really was coming to the Linux kernel motivated me to get started.

Coming From Go

For about the last year I’ve been working in Go. At this point, I’m what I’d call proficient, even good, in it, but I can’t say I like it. There is a lot to like about Go, but for me, and my development style, there are some key dislikes too. Generally, my issues are around code quality and maintainability resulting from redundant boiler-plate code and generally too open-ended structure.

My First Rust

Previously I’ve completed Rust tutorials, but to continue learning I wanted a specific development goal. I chose a port of an existing Go app I wrote: cryptoport. The app is simple but incorporates a nice mix of technologies: JSON, HTTP, file IO, data types, text formatting, text colorization, etc. So I began the creatively named rcryptoport.

My Early Impressions of Rust

Community

Rust has a strong community out there, with good information readily available.

The Tool Chain

I turned to my favorite installer, asdf, and found a Rust plugin that worked flawlessly out of the box.

The installation was painless.

Cargo worked as advertised, and nicely integrated into my IDE (IntelliJ).

The tools feel generally well-conceived, well maintained, and actively improving.

crates.io rocks.

The Language

I like Rust.

Its syntax while a bit rich is fathomable.

The type system is strong and compile-time.

It supports generics well and without fuss.

It has decent, albeit simplistic support for code organization and a workable package/module system.

The compiler does the heavy lifting and gives useful feedback. The messages are a bit cryptic initially but useful once understood.

Compile times are acceptable, especially considering how much is done there.

It has a decent testing process well integrated.

Specific Likes

Rust is demanding, if you’re doing things badly it loudly complains, and while it may be maddening at times, when you get things right you have a sense of confidence. The generics were powerful without adding too much indirection and abstraction.

Challenges

Rust’s memory ownership model is rigorous and rigorously enforced. As an inexperienced developer, I tripped over it repeatedly. In particular, Rust’s closures, and their memory ownership rules, all but thwarted me. I struggled to work out memory ownership when iterating data structures and applying closures to do things like flat mapping. I’ve still got a lot to work on there, but for now, I fell back on simpler for loops and got things done.

Other challenges revolved mostly around finding answers to questions. There’s good documentation and an active and helpful community, however, Rust does have distinctive approaches to things and employs some somewhat unique methods and idioms. At times I was stumped, not where to go for answers, but on what, or at least how to describe what I was trying to find out.

Summary

I really like Rust. While it’s not easy, I feel it’s a language that you get directly back from it the effort you put in. For my first efforts, I got a clean, functional, reliable result. Additionally, it was 30% of the size and measurably faster than the Go program I ported, a program I’d put far more time and effort into. I look forward to continuing learning and using Rust.