First thoughts about Rust

Introduction

I wanted to try new programming language. A language that is trivial and complex at the same time. Trivial to write fast, complex when struggling with performance or when you want state of art architecture.

Baby steps

This week I decided to try Rust . Rust is an expression-based language. What this mean? In general expression is collection of symbols that jointly express a quantity (or simply expression produce at least one value). But there are also statements which may be smallest standalone elements of an programming language or in other words statements are building blocks of the program.
In Rust everything is an expression, but in general we have two kind of statements. First is an binding statement (for example statement declaration) and second is expression statement, which purpose is to turn any expression into statement (for example adding ; at the end of the line). Why I even write this? Look at this if example which is statement.

If expression
1
let y = if x == 5 { 10 } else { 15 }; // y: i32

Notice that there are no semicolons after 10 and 15. This means that those are expression, and ‘if’ is an expression to, which mean that you can assign if result to y.

The basic program

After reading the first part of the Rust Book I decided to write my first program. I decided to write quick sort. Here is the code.
Lessons learned:

  • Writing a program without IDE and relay only on docs and error codes its very valuable for your learning progress.
  • Cargo, which is Rust build system is intuitive. Out of the box test and benchmark support is another advantage.
  • Primitives like in C. Good when struggling with performance. Bad when want to write fast.
  • Pointers like in C. Dangerous, but powerful toy. In next section there is a few words about how Rust extended pointer that I knew from C.
  • I didn’t like the ‘newtype’, that let you create a new type that’s similar to another one. The concept is good, but after this example, I would say I won’t use it (in most of the cases), because cost of difficulty in extracting value, is not worth providing this kind of type safe:
1
2
3
let length = Inches(3);  
let Inches(integer_length) = length;
println!("In inches size {}", length);
  • I didn’t like that Rust has two main types of strings: &str and String.

Memory management

Rust is about performance. Many of abstractions are done at compile time. There is said that new programers are fighting with compiler. I can confirm that. Once you gain more experience, it is all becoming easy for you. I have to admit that I’ve similar situation with Scala.

Experience of learning my first programming language came to me when in book pass-reference-by-value was discussed.
Rust take pointers to the whole new level. There are mutable references, boxes and more.
But in fact pointers are an introduction to Rust memory aspect such as: Ownership, Borrowing, Boxes and Lifetimes.

I’ve great time playing around and checking what will work and what not. This is a recommended part of the book and this article for further reading.

For me it was good learning journey to read and try new Language. What will be next? Maybe Go or Haskell.

Photo credit: Rust Car, Rust Nut

Why you should attend Jitter on MCE?

Jitter workshop event is a part of Mobile Central Europe Conference. It is a one day event full of attractions. Each workshop is repeated, so you can attend to two different workshops.

So why, you should attend Jitter?

  • You can meet cutting edge technology like Emberlight or Wunderbar.

  • You can co operate with you new friends to do amazing stuff.

I have an opportunity to take part in “Cardboard Design” workshop, where mentors where Wiesław and his friends. 

We were working in groups. Our goal was to visualise music using arduino, few servomotors and of course cardboards. We totally unleashed our imagination. Effects was amazing. We have used 100% of our creativity.

Besides that, event took place in a film studio. Raw and unpolished style. It give me more energy to work. But, there was a few defects. It was loud and cold, but organisers do everything to minimize those effects.

Movie studio moments before conference

I am definitely looking forward for next Jitter on next year MCE