A Journey to Rust Lang — From Kotlin/Java

Jonathon Scanes
The Startup
Published in
5 min readDec 14, 2020
Photo by Sparsh Karki from Pexels
Photo by Sparsh Karki from Pexels

This is my documented journey of learning a new programming language in 2020. I have not had the urge to learn a new language for quite some time. The last language was Kotlin but I’m not really counting that since I was able to learn it from the comfort of the already familiar JVM. Rust however is a completely new platform that otherwise requires you to leave everything you know behind (unless you inter-op with C, which I am not). It is opinionated and I’m excited about that.

I’m also excited about the notion of documenting my journey as I learn something entirely new. I’ll make posts as I encounter natural stages of my understanding of Rust and will reflect on key comparisons coming from a language like Kotlin or Java. If you’re a Kotlin or Java dev and thinking about learning Rust then be sure to follow my journey.

Why learn Rust?

Keen to learn something new

I enjoy learning things but its been a while since I’ve learned something new within my field. Over the past year I’ve enjoyed learning Kotlin and its Standard Libraries and concepts, particularly Coroutines. The API is awesome with lots of great documentation, code samples, and community discussion.

What has been the most enjoyable though is learning the quirks that aren’t explicitly documented but are just part of the nature of Kotlin’s approach to concurrency. The intermingling of your background knowledge and understanding of concurrency programming also makes this journey more interesting.

Having learned structured concurrency in Kotlin, written concurrent Kotlin to production, and written an open-source distributed streaming platform in Kotlin (Kerala), I’m eager to encounter new learnings but this time with a completely new platform, Rust.

Preparing for future demand

It’s a really interesting exercise to sit and think about the future and make a set of predictions. It forces you to think about trends (past+current), industry demands, and emerging tech. When I sit and think, one statement comes to mind:

There is a class of problems emerging within industry that demand safety, correctness and performance.

I think a lot of the low-level systems we so heavily depend on — operating systems, kernels, drivers, etc — will start being rearchitected in platforms that offer improved reliability, correctness and safety while also maximizing performance. More mission critical software will be written as the accessibility of industries like Space begin to accelerate. There will be increased demand for engineers that can write that performant mission critical code as the industry requires nothing less. Currently, I think a lot of these industries use C/C++.

With that in mind, the tools in my arsenal do not offer that kind of programming model. You definitely won’t see Kotlin being used for anything beyond Android apps and maybe web services.

Another interesting area in Rust is actually in the web, with WebAssembly (WASM). Mozilla had a JavaScript optimizer that took JavaScript code and optimized it based off quirks of the ECMA Script spec. The optimizer was called asm.js. Mozilla realized that instead of compiling all of these languages to JavaScript, why don’t we replace JavaScript with a virtual machine that can execute machine-code as portable compilation target. Because Rust and WebAssembly are from Mozilla, there is an interesting coupling happening between WASM and Rust. Rust will definitely have an interesting part in WASM adoption along with Edge Computing.

A tool to enable me to do more

I haven’t written any C or C++ for years. The industry (Space) that I want to work in requires experience with systems level programming languages like C/C++. While I could become proficient with C or C++, I don’t think that is the right move and while I do love learning, I just couldn’t be arsed learning all the nuances of the different C versions in 2020. To be honest, the C/C++ dev experience is a little too raw for me and I’d prefer something that offers clean and modern tooling to ease my transition from a high-level language like Kotlin and Java.

At the same time though, I don’t want to sacrifice the ability to write low-level systems code. While the industry largely uses C/C++, I am banking on them having some adoption of Rust.

Becoming a Rust expert

‘Expert’ is probably a stretch but I’ll still aim for that. Where to begin learning Rust?

#1 The Book

I’m going to start on the book and work through the tutorials there. This will introduce you to all the need-to-knows and explainers for novel Rust concepts.

#2 Familiarity with the docs

Getting comfortable with the languages documentation and writing style is useful. I’ll probably spend some time playing around with the standard library, extending on the code written from “the book”. Knowing how the docs are structured will save me time down the road and also helps to contribute to that more long-term goal of writing idiomatic Rust.

#3 Advanced concepts

Since knowing the basics I will be looking to understand more of the advanced aspects of the language. To satisfy this I will head over to Amazon and pick up a book that provides a deeper look into the language.

#4 A project

Having all this knowledge it’s kind of useless until you put it into practice by thinking for yourself. Probably most of the stuff by now would have been directed by somebody else. Starting an actual project from scratch in Rust with no prior art will throw you into the deep end and solidify all of that knowledge. Knowing me, the project will be something complex, but I will try and fight the urge and build something simpler.

#5 Idiomatic Rust

One long-tail with Kotlin was writing actual idiomatic Kotlin – how the language designers intended. Coming from Java, you end up writing Java-style Kotlin with complete ignorance to all of the features that Kotlin provides. Writing a language idiomatically is something that cannot be learned overnight. It’s a continued effort and for me it came from observation — looking at other peoples Kotlin code helped me a lot. Additionally, becoming really familiar with the language is going to be a big help as well.

One thing that I do think is in my favor coming to Rust is that I have no major influences or style in terms of managing memory since this has always been handled for me by a garbage collector. With Rust’s memory management model is very opinionated (a good thing) and programmers coming from C can sometimes have a hard time coming to terms with this opinion; often end up writing C-style Rust. I don’t think I’ll have this problem since it’ll be a clean slate; I’m a complete noob!

Having said that, I’m going to miss Kotlin Coroutines, and I do foresee facing challenges when becoming accustomed to Rusts concurrency model.

Thanks for reading – I look forward to keeping you posted with my progress!

Photo by SpaceX from Pexels

--

--

Jonathon Scanes
The Startup

Too many interests to list. I love snowboarding, writing code and my amazing wife — www.jnthn.dev