Slide 1

Slide 1 text

MY GOOD FRIEND RUST Matthias Endler trivago

Slide 2

Slide 2 text

How to write the word Mississippi?

Slide 3

Slide 3 text

Mississippi Sebastian is stupid. How to write the word Mississippi?

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Oh please tell me more about Matthias Endler! } Düsseldorf, Germany } Backend Engineer at } Website performance } Hot Chocolate @matthiasendler mre https://matthias-endler.de

Slide 9

Slide 9 text

Programming is easy! People pay me for that!? What’s a void pointer? Ooooh… What if programming was no fun? There is no god. Code is beautiful. Here’s a lollipop. Meh… I know nothing about programming. That’s okay. What I learned from other languages BASIC PHP C Java C++ Python Ruby Scala Haskell Go

Slide 10

Slide 10 text

http://doom.wikia.com/wiki/John_Carmack

Slide 11

Slide 11 text

Logo by johndory from http://www.freepik.com/free-vector/crabs-pattern-design_1093131.htm Funded by Mozilla First version: 2010 Version 1.0: May 2015 Current stable version: 1.20 High-level on bare metal Rust

Slide 12

Slide 12 text

Web Low-level Functional

Slide 13

Slide 13 text

PHP
 Python Ruby C C++ Clojure Haskell

Slide 14

Slide 14 text

C C++ Clojure Haskell Safety,
 Rapid prototyping

Slide 15

Slide 15 text

Clojure Haskell Safety,
 Rapid prototyping Total control,
 Performance

Slide 16

Slide 16 text

Safety,
 Rapid prototyping Total control,
 Performance High-level abstractions

Slide 17

Slide 17 text

Safety,
 Rapid prototyping Total control,
 Performance High-level abstractions Rust

Slide 18

Slide 18 text

Rust vs Python/Ruby/PHP } Better Performance } Lower memory footprint } Concurrency without overhead } Type system } Easily embeddable into existing projects } Minimal runtime } No garbage-collector

Slide 19

Slide 19 text

Rust vs Python/Ruby/PHP } Better Performance } Lower memory footprint } Concurrency without overhead } Type system } Easily embeddable into existing projects } Minimal runtime } No garbage-collector

Slide 20

Slide 20 text

Rust vs Python/Ruby/PHP - Performance https://blog.sentry.io/2016/10/19/fixing-python-performance-with-rust.html

Slide 21

Slide 21 text

Rust vs Python/Ruby/PHP - Type System def quicksort(values): if not values: return [] else: pivot = values[0] less = [x for x in values if x < pivot] more = [x for x in values[1:] if x >= pivot] return quicksort(less) + [pivot] + quicksort(more) print(quicksort([4, 2, 1, 5])) # [1, 2, 4, 5] print(quicksort("hello")) # ['e', 'h', 'l', 'l', 'o'] print(quicksort(-1)) Traceback (most recent call last): File "sort.py", line 12, in print(quicksort(-1)) File "sort.py", line 5, in quicksort pivot = values[0] TypeError: 'int' object is not subscriptable

Slide 22

Slide 22 text

fn quicksort(values: Vec) -> Vec { let pivot = match values.get(0) { Some(v) => v, None => return vec![], }; let less = values.iter().filter(|&e| e < pivot).map(|&e| e).collect(); let more = values.iter().filter(|&e| e > pivot).map(|&e| e).collect(); [quicksort(less), vec![*pivot], quicksort(more)].concat() } Rust vs Python/Ruby/PHP - Syntax def quicksort(values): if not values: return [] else: pivot = values[0] less = [x for x in values if x < pivot] more = [x for x in values[1:] if x >= pivot] return quicksort(less) + [pivot] + quicksort(more)

Slide 23

Slide 23 text

Rust vs Python/Ruby/PHP - Concurrency prime_map = {n: is_prime(n) for n in range(400_000)} Runtime:
 9min 35s def is_prime(n): if n < 2: return False for d in range(2,n): if n % d == 0: return False return True

Slide 24

Slide 24 text

Rust vs Python/Ruby/PHP - Concurrency Python Rust fn is_prime(n: u64) -> bool { match n { 0...1 => false, _ => { for d in 2..n { if n % d == 0 { return false; } } true } } } def is_prime(n): if n < 2: return False for d in range(2,n): if n % d == 0: return False return True

Slide 25

Slide 25 text

Rust vs Python/Ruby/PHP - Concurrency fn is_prime(n: u64) -> bool { match n { 0...1 => false, _ => !(2..n).any(|d| n % d == 0), } } def is_prime(n): if n < 2: return False for d in range(2,n): if n % d == 0: return False return True Python Rust

Slide 26

Slide 26 text

fn is_prime(n: u64) -> bool { match n { 0...1 => false, _ => { for d in 2..n { if n % d == 0 { return false; } } true } } } Rust vs Python/Ruby/PHP - Concurrency let prime_map: HashMap = (1..400_000) .map(|n| (n, is_prime(n))) .collect(); Runtime:
 54 seconds

Slide 27

Slide 27 text

fn is_prime(n: u64) -> bool { match n { 0...1 => false, _ => { for d in 2..n { if n % d == 0 { return false; } } true } } } Rust vs Python/Ruby/PHP - Concurrency (using rayon) let prime_map: HashMap = (1..400_000) .into_par_iter() .map(|n| (n, is_prime(n))) .collect(); Runtime:
 9.6 seconds

Slide 28

Slide 28 text

Python Rust Rust parallel Runtime (seconds) Rust vs Python/Ruby/PHP - Concurrency

Slide 29

Slide 29 text

} Memory safety } Package manager (cargo) } High-level language concepts } Easily embeddable into existing projects } Fearless concurrency } Strong compiler checks } No undefined behavior Rust vs C/C++

Slide 30

Slide 30 text

#include int *get_num(void) { int num = 1234; return &num; } int main() { int* num = get_num(); printf("%d", *num); } fn get_num() -> &i64 { let num = 1234; return &num; } fn main() { let num = get_num(); println!("{}", *num); } C Rust warning, but will execute error, will not execute Rust vs C/C++ - Memory safety

Slide 31

Slide 31 text

Rust error message: Ownership of your data must be clear at all times (No worries, the compiler will help you with that) Rust vs C/C++ - Memory safety

Slide 32

Slide 32 text

Rust vs C/C++ - Memory safety

Slide 33

Slide 33 text

Rust vs C/C++ - Memory safety https://cacm.acm.org/magazines/2017/10/221326-a-large-scale-study-of-programming-languages-and-code-quality-in-github/fulltext

Slide 34

Slide 34 text

Rust vs C/C++ - Memory safety https://cacm.acm.org/magazines/2017/10/221326-a-large-scale-study-of-programming-languages-and-code-quality-in-github/fulltext

Slide 35

Slide 35 text

} Zero-cost abstractions } No garbage-collector } No legacy Rust vs Haskell/Clojure/Kotlin…

Slide 36

Slide 36 text

Rust vs Haskell/Clojure/Kotlin… - Zero cost abstractions fn print_hash(t: &T) { println!("The hash is {}", t.hash()) } print_hash(&true); // instantiates T = bool print_hash(&12_i64); // instantiates T = i64 // The compiled code: __print_hash_bool(&true); // invoke specialized bool version directly __print_hash_i64(&12_i64); // invoke specialized i64 version directly

Slide 37

Slide 37 text

Rust vs Haskell/Clojure/Kotlin… - Laziness foldl (+) 0 [1..1000000::Integer] https://wiki.haskell.org/Memory_leak#Building_up_unevaluated_expressions (1..1000000).sum() Haskell Rust

Slide 38

Slide 38 text

Safety,
 Rapid prototyping Total control,
 Performance High-level abstractions

Slide 39

Slide 39 text

} Syntax (a bit) } Documentation/Books/Workshops } Missing tooling (IDEs, Debuggers,…) } Missing libs (help out!) } Many core libs are still < 1.0 } Steep learning curve (Fighting with the borrow checker) } SIMD support } … Rust improvement areas

Slide 40

Slide 40 text

Rust improvement areas Understanding the borrow checker Difficulty Time

Slide 41

Slide 41 text

Who’s using Rust anyway? Background image by Neil Howard ((https://flic.kr/p/nSSuUd)

Slide 42

Slide 42 text

} Firefox } Dropbox } Visual Studio Code } npm } Facebook (kind of) } Google (kind of) } https://www.rust-lang.org/en-US/friends.html Who’s using Rust anyway?

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Rust Community

Slide 45

Slide 45 text

Swear words in Reddit comments per programming language Source: https://github.com/Dobiasd/programming-language-subreddits-and-their-choice-of-words

Slide 46

Slide 46 text

Most loved language according to Stack Overflow 2016 Rust Swift F# Scala Go Clojure React Haskell Python C# Node.js 62.5% 62.0% 59.6%

Slide 47

Slide 47 text

Most loved language according to Stack Overflow 2017 Rust Smalltalk TypeScript Swift Go Python Elixir C# Scala Clojure JavaScript

Slide 48

Slide 48 text

Rust is an incredible community of people who ❤ programming. They all just happen to use the same programming language.

Slide 49

Slide 49 text

Matthias Endler matthias-endler.de
 trivago [email protected] Rate my talk please <3
 Thanks to Thomas Künneth for lending me the clicker!