Learning Rust As Go Engineer

Pramono Winata
Level Up Coding
Published in
6 min readMay 15, 2024

--

image taken from: https://bitfieldconsulting.com/posts/rust-vs-go

Rust?
Some of you might have heard about it, and no, it is not that survival game called Rust.
Rust is a programming language that has been the most admired programming language in stackoverflow survey for several years now.
It has been intriguing me since several years ago but i just recently got the chance (or more like the motivation) to try and learn it.

I have spent my last 5 years mostly on Go, hopefully Rust will not be too rough for me 🫠.

Learning Source So Far

Photo by Glenn Carstens-Peters on Unsplash

The first thing that i started off is reading rust booklet documentation https://doc.rust-lang.org/book/
It acually gives a bit of light on rust basic, but getting into further topic, just reading on the documentation is not enough.
When i started to find more references on how people are learning rust, i stumble through the repository called rustling https://github.com/rust-lang/rustlings, which in my opinion is one of the best place to start learning Rust.

Rust So far..

Photo by Matt Foxx on Unsplash

Having experienced several programming languages like C/C++, Java, Kotlin and at the latest Go, simple thing like syntax does not really give me much difficulty since Rust format does not differ that much with the usual programming language. Declaring variables and the control flow are more or less pretty much the same.

Learning a programming language does not stop there though. Syntax is just the tip of the iceberg.
To really understand the programming language we need to delve deeper and get to know what does the language offer.

Rust sure do gives out quite some new things and also some stuff that is also can be found in the other programming languages.
Here are some notable things i found during my time learning Rust:

  1. Rust Ownership
    Ownership is one of the rust main feature provided by the language.
    This mechanism allow rust to be a very memory safety programming language.
    This concept is pretty new to me since i have never seen this on any programming language, you will find yourself playing around with reference learning about ownership.
  2. Options and Error Handling
    Options is kinda like a tuple which looks like this Result<String, String> and this pattern is also commonly used for error handling.
    At first though if you came from Go-Background it might look familiar with error handling in Go (i.e: returning res,err in function).
    In truth though, it feels like learning something entirely new where you will be doing tonnes of options constructing with OK or Err .
  3. Generics And Traits
    Rust has a simillarity with Go with the OOP concept, such as it doesn’t have class on it owns also.
    The way the handled it is with the use of Generics and Traits.
    If Go have interface then Rust have traits which serves a very simillar purpose.
    The concept of both Generics and Traits are pretty straightforward in Rust itself, albeit rust does traits in more simmilar manner with Java compared to Go.
  4. Rust embrace functionalty
    Most of the time transforming and looping in Go is done in a very traditional manner, whereas when you have been delving in Rust you will find that Rust is very functional in its paradigm when dealing with looping and data manipulation.
    Rust heavily introduces the use of iteration and function such that enables data modification of an array with a single line (i.e: .map(), .filter() ).
    If you played around javascript before especially react, i am sure you are pretty familiar with this concept (psst reducer).
  5. Smart pointer
    Rust introduces a data structure that help us to maintain an object reference and ownership, that structure is called smart pointer.
    One of the easiest example that i can provide is the data structure called arc , which can be used to maintain an object atomicity.
    Rust also provides several other structure for this, one in particular is called Cow, which puzzled me until i found out that it is the abbreviation for Clone-On-Write (like.. seriously, cow?).
    This honestly is a very new concept to me and i am still not sure the practical uses for most of these data structures.

There might be some other small parts that i didn’t add in here but those were some notable things i found out while learning Rust.

Impression On Rust

Photo by Daniel K Cheung on Unsplash

Having used Golang for 5 years now, my first impression on Rust is the difference in the learning curve.
One of the main thing that Golang is great at is their simplicity meanwhile Rust is very challenging in a way that making your code compilable is an achievement.

On the other hand simplicity does have their pros and cons.
While Rust is pretty complex with their memory management, it does give you better ability to prevent memory related issue.
In Rust the compiler might be your biggest enemy at time, but it really is just like a strict parent.

Rust is also pretty library heavy and very functional heavy where they often uses their functions (like map, filter, etc) to modify their objects. To fully utilize Rust it is better to fully understand that concept.
Unlike Golang where the library is pretty minimalistic so you will be doing most of the operation in traditional way.

What is next?

Photo by Tim Mossholder on Unsplash

I feel like there is still a long way to go to learn Rust.
Reviewing the rustling again might be my next step after this, there are still a lot of things that question my mind, especially that i got some help from chatGPT to finish the rustlings (all hail AI).

There are some suggestions on Books too like The Rust Programming Language , i might be looking into that but i doubt i will finish the book though since most of the books that i started i never finished it.

Most probably i will start doing a small project using Rust, maybe a small backend crud api? So i can also take a look at Rust capability in a somewhat real working environment.

What i have shared today is my perspective towards the Rust and i am still pretty new to the language itself so i can’t really share much myself.
But i do hope that this can provide some insight to any of you guys or maybe give the motivation for you guys to also start and try Rust yourself.

I might post more my learnings in the future when i got to try more about Rust, i sure hope do my journey in Rust doesn’t just end here!

As always thanks for reading my article through the end, i truly hope that this can be useful for you.
Stay humble and keep on learning!

--

--