rust with confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ......
TRANSCRIPT
![Page 1: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/1.jpg)
RUST WITH CONFIDENCERUST MEETUP COLOGNE – FEB 2016 – PASCAL HERTLEIF
�1
![Page 2: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/2.jpg)
WHO IS THIS GUY ANYWAY?
PASCAL HERTLEIF▸ Web dev by day – come talk to me
about that, too!
▸ Following Rust since 2014
▸ eBook versions of The Rust Programming Language
▸ You should cargo install cargo-edit (this includes cargo add and cargo list)
2
![Page 3: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/3.jpg)
SYSTEMS PROGRAMMING IS SCARY
3
![Page 4: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/4.jpg)
HELPFUL ERRORS, THE GOOD KIND OF ERRORS
e.rs:46:14: 46:23 error: `node.elem` does not live long enough e.rs:46 &node.elem ^~~~~~~~~ note: in expansion of closure expansion e.rs:45:23: 47:10 note: expansion site e.rs:44:38: 48:6 note: reference must be valid for the anonymous lifetime #1 defined on the block at 44:37... e.rs:44 [code excerpt] e.rs:45:30: 47:10 note: ...but borrowed value is only valid for the scope of parameters for function at 45:29 e.rs:45 [code excerpt]
4
![Page 5: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/5.jpg)
PROGRAMM REFACTOR
COLLABORATE
OUR HUMBLE GOAL
WITHOUT FEAR
5
![Page 6: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/6.jpg)
PROGRAMM REFACTOR
COLLABORATE
OUR HUMBLE GOAL
WITHOUT FEAR
6
![Page 7: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/7.jpg)
MEMORY SAFETY CONCURRENCY ABSTRACTION STABILITY
Rust Core Team, August 2015
WHAT MAKES RUST AWESOME 7
GARBAGE COLLECTION DATA RACES
OVERHEAD STAGNATION
WITHOUT
![Page 8: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/8.jpg)
DATA-PARALLELISM? WHY NOT?
use rayon::par_iter::*;
fn sum_of_squares(input: &[i32]) -> i32 { input.par_iter() .map(|&i| i * i) .sum() }
8
![Page 9: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/9.jpg)
PROGRAMM REFACTOR
COLLABORATE
OUR HUMBLE GOAL
WITHOUT FEAR
9
![Page 10: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/10.jpg)
HELP THE COMPILER HELP YOU
AUTOMATED TESTS? ▸ Use type system to prevent ‘structural’ bugs (incl. memory unsafety)
▸ Write tests for business logic
▸ Write documentation for people
▸ Code snippets in documentation are executed like tests!
▸ Suggestion: Trivial test cases as docs, edge cases as #[test]s
10
![Page 11: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/11.jpg)
TO ERR IS TO BE HUMAN, BUT COMPILERS NEVER FORGET
The Rust Programming Language (1.5)
AUTOMATION FOR THE PEOPLE 11
![Page 12: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/12.jpg)
CLIPPY LINTS ALL THE THINGSLINTS, LINTS EVERYWHERE
LET THE COMPILER DO MORE WORK▸ Lints are compile-time checks
▸ Some are enabled by default
▸ #![deny(missing_docs)] makes every crate better
▸ Clippy adds 80 96 100 109 more lints
12
![Page 13: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/13.jpg)
CLIPPY LINTS ALL THE THINGS
HOW FAR DOES THIS GO?
13
(Oct 28, 2015)
![Page 14: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/14.jpg)
PROGRAMM REFACTOR
COLLABORATE
OUR HUMBLE GOAL
WITHOUT FEAR
14
![Page 15: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/15.jpg)
DON'T MAKE ME THINK ABOUT BOILERPLATES
MAKE YOUR CODE BASE INVITING TO NEW DEVELOPERS▸ Follow the default structure for Cargo projects
▸ Cargo.toml with lots of metadata, incl. authors and license
▸ src/
▸ tests/
▸ examples/
15
![Page 16: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/16.jpg)
YOUR CRATES SHOULD MAKE PEOPLE FEEL FUZZY ON THE INSIDE
MAKE YOUR CODE BASE INVITING TO NEW DEVELOPERS▸ Format your code sanely
▸ Just use rustfmt for everything
▸ Have a Readme that gives an abstract overview of the project
▸ Run automated tests for every commit and pull request
16
![Page 17: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/17.jpg)
THANKS FOR LISTENING
WHAT MAKES RUST AWESOME
ANY QUESTIONS?
17
![Page 18: Rust with Confidence · 2020. 5. 25. · web dev by day – come talk to me about that, too! ... refactor collaborate our humble goal without fear 5. programm refactor collaborate](https://reader034.vdocuments.net/reader034/viewer/2022051900/5feec296dcf2cb31c01ce2fa/html5/thumbnails/18.jpg)
▸ Cover image by Keith Misner https://unsplash.com/photos/v99lFTVp_ws
▸ Clippy https://github.com/Manishearth/rust-clippy
▸ Rayon https://github.com/nikomatsakis/rayon
▸ Rust in 2016 http://blog.rust-lang.org/2015/08/14/Next-year.html
REFERENCES
18