Rust vs Scala

By clecam, 22 August, 2024

I used to write a POC in Rust in 2020. At this time there was no LLM to help us learn a new language. My first steps were not so easy. At this time, I discovered the concept of borrower checking and ownership. Coming from Scala, I was used to full immutability too. In Rust, we have to choose even if the default is immutability. And after 3 months, I stopped using Rust.

In June 2024, I studied LLMOps. There is a great course on Coursera named LLMOps. I understood I have to study Rust more deeply for a few reasons:

  • Rust is fast and safe
  • Rust is the way to go for deploying LLMs
  • Rust has several machine learning libraries

I decided to read with attention the documentation here. This documentation is very well done. It explains (I just mention what may be new from a Scala developer like me):

  • Ownership and borrow checker
  • Struct and enum
  • Error management
  • Unit and Integration test
  • How to write documentation
  • Documentation testing
  • Trait (used mainly as typeclasses).
  • Generics and bounded trait, super trait
  • Lifetime
  • Closure difference with functions
  • Cargo commands
  • Structure like Box, Rc, Refcell and how to avoid memory leaks with Weak when using cycles
  • Some patterns like interior mutability
  • Multithreading with channels, Rayon and Arc / Mutex
  • An overvciew of declarative and procedural macro

We can see that this documentation is very complete and well done.

For the moment, the only difficult I have concerns the Mutex approach for multithreading. This reminds me C / C++ way of programming that was harmful. Here there is the safety of Rust. The difficulty will be more I think in managing correctly the ownership and borrows system so that the program get compiled ! Here the help of LLM will make it easier.

I am not very fond of Mutex in fact. What I understand is that the core of Rust is minimal and the libraries (crates) developed around Rust will bring new features like coroutines. But due to its borrowing and ownership system, Rust approach will be different from Scala.

I go further by reading two books:

  • Rust in Action
  • Rust advanced techniques

For the first one, we have to wait the second part to enter into examples. The first part just recall mainly what is explained in the Rust documentation. As regards the second one, it explains design patterns in Rust and I found it interesting.

This is a good starting point. I see there are other topics to learn:

  • WASM
  • Web project
  • GUI application
  • Video games

Let us go step by step by coding a real project in Rust.

Tags

Comments