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

Gerrit and maven release plugin

There is a time in your project when you start using Gerrit code review system. When you have maven release plugin to make release, you can be very surprised when you see:

1
2
3
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] Permission denied (publickey).

This is a situation when we use ssh connections to gerrit. But, when you try to push something to master (ignoring code review), it works! How is that possible?

You probably have in your gitconfig an ssh URL with your user name. But in your project SCM (in pom.xml) you do not have your user name. What user name maven release plugin use? Your computer account name, which is in most cases different than your Gerrit user name.

How to repair it? Define a file in .ssh/config directory with content:

1
2
3
4
Host gerrit
HostName YOUR_GERRIT_HOST
Port YOUR_GERRIT_PORT
User YOUR_GERRIT_USER_NAME

There may be a lot of other reason why you have Premission denied, but this was the hardest I’ve ever seen.

GNU sed and xpath on OS X

In my team, there is 20% of OS X machines, rest are linuxes. We share one script, that everyone on our team uses.

That script was written by some guy on Ubuntu and guess what? GNU versions of those programs (sed and xpath) are not compatible with BSD versions. The script was failing :(

I was trying to improve the script, but forget about it. Just use GNU programs.

To install gnu sed on osx via homebrew type the following:

GNU Sed
1
brew install gnu-sed --with-default-names

To install gnu xpath on osx via homebrew type the following:

GNU Xpath
1
2
3
4
brew tap concept-not-found/tap
brew install xpath
mv /usr/local/bin/xpath /usr/local/bin/osx.xpath
sudo ln -s /usr/local/Cellar/xpath/1.13-7/bin/xpath /usr/local/bin/xpath

Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig

This is not a book about motorcycle maintenance. This is not only a book about the zen. This is not only a novel. This is mostly a book about philosophy. But philosophy is served in nice form.

This book took me to journey though a USA. I was feeling that I was an passenger of this journey. I was feeling that I was traveling with author that talks to me about philosophy.

During this journey, the idea of quality and value was assembled and dissembled many times, like motorcycle parts. It was mostly presented in straightforward form and readable manner. It has a good points to think about it. But, some parts were misleading for me.

I read this book because I need a change from normal technical book. My score for that book is 4 of 5 points.

Photo credit