The Rust programming language has become a popular choice amongst software engineers since its release in 2010. Besides being something new and interesting, Rust promised to offer exceptional performance and reliability. In particular, Rust achieves memory-safety and thread-safety through its ownership model. Instead of runtime checks, this safety is assured at compile time by Rust's borrow checker. This prevents undefined behaviour such as dangling pointers!
println!("Hello World!");
I first encountered Rust sometime around 2015 when I was updating my teaching materials on memory management in C. A year later in 2016, I implemented a simple multi-objective evolutionary algorithm in Rust as an academic exercise (available: https://github.com/shahinrostami/simple_ea). I didn't have any formal training with Rust, nor did I complete any tutorial series, I just figured things out using the documentation as I progressed through my project.
Some example code from this project takes ZDT1 from its mathematical expression in Equation 1
to the Rust implementation below.
pub fn zdt1(parameters: [f32; 30]) -> [f32; 2] {
let f1 = parameters[0];
let mut g = 1_f32;
for i in 1..parameters.len() {
g = g + ((9_f32 / (parameters.len() as f32 - 1_f32)) * parameters[i]);
}
let h = 1_f32 - (f1 / g).sqrt();
let f2 = g * h;
return [f1, f2];
}
It was interesting to see that since writing this code in 2016, some of my dependencies had been deprecated and superseded.
My greatest challenge was breaking away from what I already knew. Until this point, I was familiar with languages such as C, C++, C#, Java, Python, MATLAB, etc., with the majority of my time spent working with memory managed languages. I found myself resisting Rust's intended usage, and it is still something I'm working on.
Now that I am about to commence my sabbatical from my University post, I've decided to try Rust again. This time, I'm going to write a book which focusses on using Rust and Jupyter Notebooks to implement algorithms and conduct experiments, most likely in the fields of search, optimisation, and machine learning. Can we write and execute all our code in a Jupyter Notebook? Yes! Should we? Probably not. However, I enjoy the workflow, and making this an enjoyable process is important to me.
Note
I aim to generate everything in this book through code. This means you will see the code for all my figures and tables, including things like flowcharts.
Looking through the November commits for Evcxr and incredibly flattered to see my book mentioned! https://github.com/google/evcxr/commit/48de626bd8f6ac006f7d0f353f38ddffbe42e926 #rustlang #rust pic.twitter.com/Ti8tTWNoSQ
— Dr. Shahin Rostami (@ShahinRostami) December 7, 2020