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. - Düsseldorf, Germany - Backend Engineer at trivago - Website

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

    - Primary goal: A safer systems language - First version: 2010 - Current stable version 1.8
  3. • Provide the right abstractions • Provide awesome tools •

    Allow making mistakes • Build a helpful community System Programming can be fun!
  4. Where Rust makes sense Everywhere you want speed and safety

    • Operating Systems • Compilers • Emulators
 Encryption • Databases
 Numerics • Graphics Programming • Data Pipelines
 Finance • …
  5. 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
  6. 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
  7. #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++
  8. fn main() { let mut v = Vec::new(); v.push("foo"); let

    mut x = &mut v[0]; v.push("bar"); println!("{}", x) } RUST
  9. 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
  10. What I like about… • PHP: Package manager, Community •

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

    Python: Syntax, Libraries • Golang: Tooling, Documentation, Concurrency • C: Speed, no overhead RUST
  12. 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
  13. What sucks about Rust • Syntax (a bit) • „Fighting

    with the Borrow checker“ • Missing packages (you can help!) • probably more…
  14. My tool wishlist Unit testing: builtin Package manager Syntax highlighting

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

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

    highlighting: atom-language-rust Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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?
  25. 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:
  26. 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
  27. 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)