Languages of the future – part 1 – Rust

People always look at the next big thing. With programming languages next big thing is already created. The most popular languages that we will use in 10 years are probably already here. It took Python almost 30 years to get to the place where it is right now. I assume with newer programming languages it can take 10-15 years because everything is moving a lot faster then it was 20-30 years ago.
AI
Blog

Table of Contents

First of all, I do believe that when learning people should focus on learning about the concepts and then focus on the technology. If you want to learn about programming languages concept I can recommend notes from this course from Stanford (https://cs242.stanford.edu/f19/). However for learning we need some vehicles – languages that show some concepts better than anything else. One of the languages that I’m going to present is used to teach many new concepts that’s why I think it is worth mentioning.

Rust

Being a hackernews favorite language I wanted to know more, so I started learning about Rust and soon I realized why it is such a beloved technlogy (5 years in a row it won the most loved technology among stackoverflow users – https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-loved).

The language

The most important Rust feature is the safety guarantees it gives out of the compilation phase. What it means is that the compiler won’t let you write a program that is memory unsafe. Rust introduced concepts like borrowing (References and borrowing). It also seems that these guarantees don’t bring additional costs (they are offered as “zero-cost” abstraction) and this means that the code will be as fast as C/C++ but much safer.

The safety of the language is cool but I want ergonomics too. The first impression is that Rust is a blend of many different ideas and some of them are very useful:

almost everyhing is an expression

let x = if something {
   foo()
} else {
   bar()
}

pattern matching

let x = 5;
match x {
    1..=5 => println!("one through five"),
    _ => println!("something else"),
}

mutability by default

let immutable = 1;
 // cannot do this
immutable = 4;

// Mutable variable
let mut mutable = 1;
mutable = 4;
mutable += 2;

All of these features make Rust more similar to functional programming language than C/C++. And indeed, Rust roots go to ML family of languages (like Haskell, OCaml). Having programmed in Scala for some time I must say that this functionality feels like home.

Is Rust a functional programming language?

As mentioned in the previous paragraph – Rust borrows a lot from functional programming languages:

  • algebraic data types
  • default immutability
  • expressions
  • higher order functions / method chaining

However Rust is not a functional programming language per se. It is worth mentioning that idiomatic functional programming is not always without a cost and for what Rust is supposed to be (a systems programming language) it shouldn’t bring costly abstractions.

Compiler

Rust compiler is amazing! Apart from the obvious design choices that help the user to write safe programs the compiler really tries to help you as best it can. Let’s look at an error that I had today in the software we are building.

error[E0061]: this function takes 1 argument but 0 arguments were supplied
  --> src/events/parser.rs:32:17
   |
32 |         None => Err(),
   |                 ^^^-- supplied 0 arguments
   |

Looks normal, but there is more. The compiler suggest a fix! In 90% of the cases this fix works as expected.

help: expected the unit value `()`; create it with empty parentheses
   |
32 |         None => Err(()),
   |                     ^^

This was a simple mistake, now something that is not so trivial.

error[E0599]: no method named `user_info` found for reference `&T` in the current scope
  --> src/accum/accums/item_cooccurence.rs:29:51
   |
29 |             UserInfoType::VISITOR => Some((*event.user_info().visitor_id).to_string()),
   |                                                   ^^^^^^^^^ method not found in `&T`
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `user_info`, perhaps you need to restrict type parameter `T` with it:
   |
27 |     fn update<t: events::traits::userinfot="">(&mut self, item_counter: &VisitorItemCounter, event: &T) {
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
</t:>

What is happening here? This error says that my generic type has no method user_info. Every language can do it. But what comes after the message is a suggestion. Rust found a trait that implements this method and suggests it as an addition. Whoever made such informative errors probably saved thousands of hours of debugging.

Ecosystem

Rust comes with a set of really handy tools for development like:

It feels like people who wrote Rust and all those surrounding tools value quality and ergonomics and it pays off.

Learning

While Rust presents some new concepts and in general it is quite big and advanced language, the learning experience is better than everything I came across.

IDE support

I was quite surprised to have so many good editors available for rust. Visual Studio Code is a prefered option and works great. I also use intellij with Rust plugin and it is also good, but not as nice as vscode. The only thing that is better in intellij is refactoring.

Update: After trying both vscode and intellij with Rust plugin, I like intellij more. Visual Studio Code has many useful extensions but I slightly prefer “batteries included” approach of the latter.

Industry adoption

Created by Mozilla rust has yet to gain wide adoption in the industry. But I think it will happen very soon. The signs are all there. The major players like Microsoft, Facebook, Amazon are betting on this technology (https://www.businessinsider.com/what-is-rust-programming-language-amazon-facebook-discord-love-it-2020-6?IR=T). I believe the main driving force are people who use Rust for hobby – this is where all the love comes from in stackoverflow surveys. But the feelings are not misguided and more and more developers will be happy to work on Rust not only as side projects but also in their professional careers.

Summary

I believe Rust will stay with us for longer. It of course won’t replace Python, but it sure can replace C++ and Java for performance critical pieces of software.

Topics:

CTO / Data Scientist / Kaggle Grandmaster

CTO / Data Scientist / Kaggle Grandmaster

Other stories in category

BlogKaggle Days
4 – Nature never goes out of style!

4 – Nature never goes out of style!

4 – Nature never goes out of ...

Five continents, twelve events, one grand finale, and a community of more than 10 million - that's Kaggle Days, a nonprofit event for data science enthusiasts and Kagglers. Beginning in November 2021, hundreds of participants attending each meetup face a daunting task to be on the podium and win one of three invitations to the finals in Barcelona and prizes from Kaggle Days and Z by HPZ by HP.

Paras Varshney

16 Aug 2022

BlogKaggle Days
3 – Now you are playing with power

3 – Now you are playing with power

3 – Now you are playing with ...

"It was amazing," commented attendees of the third Kaggle Days X Z by HP World Championship meetup, and we fully agree. The Moscow event brought together as many as 280 data science enthusiasts in one place to take on the challenge and compete for three spots in the grand finale of Kaggle Days in Barcelona. Of course, we already know the winning teams that best handled the contest task. In addition to the excitement of the competition, in Moscow were also inspiring lectures, speeches, and fascinating presentations of modern equipment. As always, at Kaggle Days, a lot was going on.

Paras Varshney

16 Aug 2022

BlogKaggle Days
2 – Water Water everywhere, not a drop to drink

2 – Water Water everywhere, not a drop to drink

2 – Water Water everywhere, n...

"Happy to be part of shaping the future." "It's the Way of The Future." That is how the participants summed up another meetup organized as part of Kaggle Days, a non-profit event for data science enthusiasts who want to grow and compete for prizes under the watchful eye of top Kaggle mentors and grandmasters. The second meetup in New Delhi is behind us. Three hundred participants, more than one hundred teams, and only three invitations to the finals in Barcelona mean that the excitement could not be lacking.

Paras Varshney

16 Aug 2022