Beginning to Rust: My Experience As An R User

I talk about my first couple of months learning the coding language Rust, ostensibly for bioinformatics reasons 🦀
Author

Jason Yeung

Published

June 19, 2024

TLDR: As someone who has used R extensively for bio-medical research, learning Rust isn’t easy. Unless you develop custom tooling and work on large amounts of data where performance becomes an issue, you won’t benefit much from learning Rust. I lay out some tips to ease the process of learning and provide some useful links.

Why Rust When We Have R Or Python?

I decided to start learning Rust around 3 months ago. My interest in Rust stemmed from Twitter-timeline envy. Increasingly, bioinformatics people on my feed have been building sleek, optimal, WebAssembly-compatible programs in Rust.1 The idea of knowing Rust feeds into a big, lingering self-assertion: that I’m not a real programmer. I still won’t be after learning Rust but I’ll get to deepen my curriculum vitae’s wet-lab/dry-lab confusion even more.

I won’t harp too much about the benefits of Rust vs R/Python in bioinformatics; that’s been done well elsewhere. Generally, the situations in which R/Python excel have little overlap with tasks you would want to achieve with Rust. For many scientists, R and Python are for data-cleaning, plotting, and statistical analyses (data science applications). Rust is for creating the type of programs that require you to bust out the command line (the rest of bioinformatics I consider outside the realm of data science). Rust provides speed, performance, and stability where R and Python sometimes can’t.

Having used R for various projects, I consider myself quite fluent in R (but not a master). Having first started in Java, the initial learning curve for R and Python was much less steep than Rust’s. There are many paradigms in Rust that are simply not considerations in R or Python. Several weeks in I was frustrated that I couldn’t remember syntax well enough to even assign values to variables. Don’t be put off! You won’t need everything all at once and some of it may not be needed at all.

Me by day 7. I was once blissfully unaware of the coming frustrations. The frustration is less now but oh so present.

A Strategy For Learning

What is the optimal way to learn Rust? No idea. I can only describe my approach. If you’re looking to learn Rust as a long-term investment, worrying about optimality can keep you off the long and difficult path towards mastery you’ll be traveling down anyways. I will say, that after 3 months of inconsistent studying during leisure time, I’m finally comfortable enough to write the majority of code in simple programs from scratch. Here’s what I did:

1. Don’t spend too much time reading the Rust manual but definitely read some of it. Start coding as quickly as possible, starting with problem sets. I used rustlings but Rust By Practice seems like a solid alternative.

2. Once you develop some level of comfort reading Rust code and getting the pre-written Rust code in rustlings to run, start incorporating Rust problems from Exercism. These will force you to write more code from scratch, familiarizing you with syntax. Feel free to use a LLM like ChatGPT for help debugging but enforce rules of attempting a no-help solution before prompting and always typing out code rather than copy-pasting. 100 Exercises To Learn Rust is an alternative to Exercism.

3. If you have a problem or project in mind already, you could have a go at it relatively early in this learning process, LLM at hand. Coding anything with AI assistance is better when you can articulate the problem - in the parlance of someone who actually knows what they are doing and what they need. Depending on the complexity of your project, porting existing code written in one language into Rust should be achievable early on.


MD/PhD Student at University of Texas Medical Branch

I write about viruses, data science, and ballet.
Click home at the top of the page to see other things I’ve been working on.

Footnotes

  1. I think Dr. Rob Patro was one of the first to show up on my timeline, if not the first.↩︎