Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Matthias Endler

May 11, 2016
Tweet

More Decks by Matthias Endler

Other Decks in Programming

Transcript

  1. Why Rust?

    View Slide

  2. - Düsseldorf, Germany
    - Backend Engineer at trivago
    - Website performance team
    - Worked a lot with Python and PHP
    - Likes hot chocolate
    @matthiasendler
    Matthias Endler

    View Slide

  3. Rust
    - Created by Graydon Hoare
    - Funded by Mozilla
    - Primary goal: A safer systems language
    - First version: 2010
    - Current stable version 1.8

    View Slide

  4. System Programming
    Memory management
    Error handling
    Static Typing
    Compiling

    View Slide

  5. System Programming
    is challenging!

    View Slide

  6. • Provide the right abstractions
    • Provide awesome tools
    • Allow making mistakes
    • Build a helpful community
    System Programming
    can be fun!

    View Slide

  7. RUST: High level on bare metal

    View Slide

  8. Where Rust makes sense
    Everywhere you want speed and safety
    • Operating Systems
    • Compilers
    • Emulators

    Encryption
    • Databases

    Numerics
    • Graphics Programming
    • Data Pipelines

    Finance
    • …

    View Slide

  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

    View Slide

  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

    View Slide

  11. #include
    #include
    #include
    int main() {
    std::vector v;
    v.push_back("foo");
    auto const &x = v[0];
    v.push_back("bar");
    // Undefined behavior!
    std::cout << x;
    }
    C++

    View Slide

  12. fn main() {
    let mut v = Vec::new();
    v.push("foo");
    let mut x = &mut v[0];
    v.push("bar");
    println!("{}", x)
    }
    RUST

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  17. What sucks about
    Rust
    • Syntax (a bit)
    • „Fighting with the Borrow checker“
    • Missing packages (you can help!)
    • probably more…

    View Slide

  18. Complexity vs Speed
    • PHP
    • Python
    • Golang
    • Rust
    • C
    Faster „Easier“

    View Slide

  19. IDEs?

    View Slide

  20. Visual Studio

    View Slide

  21. Visual Studio Code using Rusty Code plugin

    View Slide

  22. Atom with language-rust plugin

    View Slide

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

    View Slide

  24. https://doc.rust-lang.org/book/testing.html
    Unit testing

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  34. https://llogiq.github.io/2015/07/15/profiling.html
    Calls
    Time

    View Slide

  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?

    View Slide

  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:

    View Slide

  37. Summary
    Lots of work to do
    But impressive start

    View Slide

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

    View Slide

  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

    View Slide

  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)

    View Slide

  41. www.meetup.com/Rust-Amsterdam

    View Slide

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

    View Slide