Why Rust?

Why Rust?

Rust is the new kid on the block. It's a system programming language that is blazingly fast and offers powerful high-level abstractions better known from dynamic languages like Ruby or Python. Rust offers memory safety without a Garbage Collector and makes low-level programming easier and more secure. I will give an introductory talk about Rust and show some of its nicest features.

---
Slides for the presentation I gave about Rust at cod{e}motion Amsterdam 2016

Ed9e9992fe069a0d3de05b69d8d187c3?s=128

Matthias Endler

May 11, 2016
Tweet

Transcript

  1. Why Rust?

  2. - Düsseldorf, Germany - Backend Engineer at trivago - Website

    performance team - Worked a lot with Python and PHP - Likes hot chocolate @matthiasendler Matthias Endler
  3. Rust - Created by Graydon Hoare - Funded by Mozilla

    - Primary goal: A safer systems language - First version: 2010 - Current stable version 1.8
  4. System Programming Memory management Error handling Static Typing Compiling …

  5. System Programming is challenging!

  6. • Provide the right abstractions • Provide awesome tools •

    Allow making mistakes • Build a helpful community System Programming can be fun!
  7. RUST: High level on bare metal

  8. Where Rust makes sense Everywhere you want speed and safety

    • Operating Systems • Compilers • Emulators
 Encryption • Databases
 Numerics • Graphics Programming • Data Pipelines
 Finance • …
  9. struct Person { first_name: String, last_name: String, age: i32 }

    impl Person { pub fn new(first_name: String, last_name: String, age: i32) -> Person { Person { first_name: first_name, last_name: last_name, age: age } } } fn main() { let mut vec = Vec::new(); vec.push(Person::new(String::from("Austin"), String::from("Powers"), 13)); vec.push(Person::new(String::from("Dr."), String::from("Evil"), 30)); for person in &vec { let result = match person.age { 0...18 => "Teenager", 18 => "Old enough to go to war", _ => "Too Old" }; } } RUST
  10. Type safety Type expression Type checking Garbage Collector C unsafe

    explicit static No C++ unsafe explicit static No Go safe implicit/explicit static Yes Rust safe implicit/explicit static/dynamic optional
  11. #include <iostream> #include <vector> #include <string> int main() { std::vector<std::string>

    v; v.push_back("foo"); auto const &x = v[0]; v.push_back("bar"); // Undefined behavior! std::cout << x; } C++
  12. fn main() { let mut v = Vec::new(); v.push("foo"); let

    mut x = &mut v[0]; v.push("bar"); println!("{}", x) } RUST
  13. fn f(x: Type) {...} fn f(x: &Type) {...} fn f(x:

    &mut Type) {...} Mutable borrow Ownership • Share as you like • read-only • one at a time • read/write Immutable borrow • Total control • read-write
  14. What I like about… • PHP: Package manager, Community •

    Python: Syntax, Libraries • Golang: Tooling, Documentation, Concurrency • C: Speed, no overhead
  15. What I like about… • PHP: Package manager, Community •

    Python: Syntax, Libraries • Golang: Tooling, Documentation, Concurrency • C: Speed, no overhead RUST
  16. What sucks about… • PHP: Syntax (a bit), legacy functions

    • Python: Package manager, 2 vs 3 • Golang: Error handling, package manager, no generics, Syntax (a bit) • C: Missing package manager, safety
  17. What sucks about Rust • Syntax (a bit) • „Fighting

    with the Borrow checker“ • Missing packages (you can help!) • probably more…
  18. Complexity vs Speed • PHP • Python • Golang •

    Rust • C Faster „Easier“
  19. IDEs?

  20. Visual Studio

  21. Visual Studio Code using Rusty Code plugin

  22. Atom with language-rust plugin

  23. My tool wishlist Unit testing: builtin Package manager Syntax highlighting

    Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  24. https://doc.rust-lang.org/book/testing.html Unit testing

  25. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  26. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  27. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion Debugging Code linter Benchmarking Profiling Code coverage
  28. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging Code linter Benchmarking Profiling Code coverage
  29. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter Benchmarking Profiling Code coverage
  30. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking Profiling Code coverage
  31. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling Code coverage
  32. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… Code coverage
  33. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… torch? Code coverage
  34. https://llogiq.github.io/2015/07/15/profiling.html Calls Time

  35. My tool wishlist Unit testing: builtin Package manager: cargo Syntax

    highlighting: atom-language-rust Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: builtin Profiling: meh… torch? Code coverage: kcov?
  36. kcov …is a code coverage tester for compiled programs, Python

    scripts and shell scripts language: rust matrix: fast_finish: true include: - rust: nightly env: FEATURES="--features nightly" sudo: false - rust: nightly env: FEATURES="--features nightly" BENCH=true sudo: false - rust: beta sudo: true after_success: | sudo apt-get install libcurl4-openssl-dev libelf-dev libdw-dev && wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && sudo make install && cd ../.. && kcov --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/hyper-* Put this into your .travis.yml:
  37. Summary Lots of work to do But impressive start

  38. We need to focus on those… • Debugging • Profiling

    • Code Coverage
  39. glium • High-level wrapper around OpenGL • Avoids all OpenGL

    errors diesel • A safe, extensible ORM and Query Builder • Operating System written in pure Rust,
 designed to be modular and secure Redox crossbeam • A collection of lock-less data structures turbine • A high-performance, non-locking, inter-task communication library written in Rust. • Go channels on steroids
  40. Bonus rr - a reverse debugger
 (http://rr-project.org/) Dash - Offline

    API Documentation browser for Mac (https://kapeli.com/dash) Crates.io reverse package lookup
 (https://crates.io/crates/serde/reverse_dependencies)
  41. www.meetup.com/Rust-Amsterdam

  42. Even more at https://gist.github.com/nrc/a3bbf6dd1b14ce57f18c http://kukuruku.co/hub/rust/comparing-rust-and-cpp