Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Node.js

Slide 3

Slide 3 text

Expressiveness Speed JS

Slide 4

Slide 4 text

Underestimated: Ubiquity

Slide 5

Slide 5 text

Client Side Server Side JS JS

Slide 6

Slide 6 text

Expressiveness Speed JS

Slide 7

Slide 7 text

Expressiveness Speed JS V8

Slide 8

Slide 8 text

Expressiveness Speed JS V8 ES6+

Slide 9

Slide 9 text

Enabling Technologies

Slide 10

Slide 10 text

Me, A Systems Programmer?

Slide 11

Slide 11 text

Me, A Systems Programmer? That's someone else's job…

Slide 12

Slide 12 text

Me, A Systems Programmer?

Slide 13

Slide 13 text

Me, A Systems Programmer? "Systems programming" sounds hard… and dangerous

Slide 14

Slide 14 text

Me, A Systems Programmer?

Slide 15

Slide 15 text

Me, A Systems Programmer? What is "Systems programming" anyway?

Slide 16

Slide 16 text

What is Systems Programming? • Programming without a GC • Programming directly against the metal, without abstraction costs • Pay-as-you-go, lightweight runtime, or no runtime • Zero-cost abstractions • When "it doesn't end up mattering" isn't true

Slide 17

Slide 17 text

That Doesn't Need to Mean • malloc and free • Assembly Language • Targeting Unix-only or Windows-only • Old-school tools like hand-crafted Makefiles • Fighting with the linker • Writing your entire application in a systems language

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Embedding, Performance, Low Memory

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Fast, Safe, Parallel

Slide 22

Slide 22 text

How Does it Work?

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Garbage Collection class  Point
    def  initialize(x,  y)
        @x,  @y  =  x,  y
    end
 end
 
 class  Line
    def  initialize(p1,  p2)
        @p1,  @p2  =  p1,  p2
    end
 
    def  length
        #  compute  length
    end
 end
 def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end

Slide 25

Slide 25 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end

Slide 26

Slide 26 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end

Slide 27

Slide 27 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1)

Slide 28

Slide 28 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1)

Slide 29

Slide 29 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1) Point.new(x2,  y2)

Slide 30

Slide 30 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1) Point.new(x2,  y2)

Slide 31

Slide 31 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1) Point.new(x2,  y2) Line.new(p1,  p2)

Slide 32

Slide 32 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1) Point.new(x2,  y2) Line.new(p1,  p2)

Slide 33

Slide 33 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end Point.new(x1,  y1) Point.new(x2,  y2) Line.new(p1,  p2) later… stop the world…

Slide 34

Slide 34 text

Garbage Collection def  length(x1,  y1,  x2,  y2)
    p1  =  Point.new(x1,  y1)
    p2  =  Point.new(x2,  y2)
    line  =  Line.new(p1,  p2)
    line.length
 end

Slide 35

Slide 35 text

Ownership

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Ownership is the Right to Destroy

Slide 44

Slide 44 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   }

Slide 45

Slide 45 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   }

Slide 46

Slide 46 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   }

Slide 47

Slide 47 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   }

Slide 48

Slide 48 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   }

Slide 49

Slide 49 text

Right to Destroy pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      println!("Title:  {}",  book.title);   } note the lack of manual memory management

Slide 50

Slide 50 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 51

Slide 51 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 52

Slide 52 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 53

Slide 53 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 54

Slide 54 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 55

Slide 55 text

Transferring Ownership pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 56

Slide 56 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 57

Slide 57 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 58

Slide 58 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 59

Slide 59 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 60

Slide 60 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 61

Slide 61 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 62

Slide 62 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   }

Slide 63

Slide 63 text

Transferring Ownership pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  Book)  {      println!("Title:  {}",  book.title);   } error: use of moved value: `book.chapters` note: `book` moved here

Slide 64

Slide 64 text

Borrowing v. To receive something with the promise of returning it

Slide 65

Slide 65 text

Return this by 5pm on Friday

Slide 66

Slide 66 text

Return this by 5pm on Friday

Slide 67

Slide 67 text

Return this by 5pm on Friday

Slide 68

Slide 68 text

Return this by 5pm on Friday

Slide 69

Slide 69 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 70

Slide 70 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 71

Slide 71 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 72

Slide 72 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 73

Slide 73 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 74

Slide 74 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 75

Slide 75 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 76

Slide 76 text

Borrowing pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  main()  {      let  book  =  read("book1.txt");      print_book(&book);      println!("Chapters:  {}",  book.chapters.len());   }   fn  print_book(book:  &Book)  {      println!("Title:  {}",  book.title);   }

Slide 77

Slide 77 text

Sub-Leasing

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Return this by 5pm on Friday

Slide 81

Slide 81 text

Return this by 5pm on Friday

Slide 82

Slide 82 text

Return this by 4:30pm on Friday

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 87

Slide 87 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 88

Slide 88 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 89

Slide 89 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 90

Slide 90 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 91

Slide 91 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 92

Slide 92 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 93

Slide 93 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 94

Slide 94 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 95

Slide 95 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 96

Slide 96 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 97

Slide 97 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 98

Slide 98 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 99

Slide 99 text

Sub-Leasing fn  main()  {      let  book  =  read_book("book1.txt");      print_book(&book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec
 }   fn  print_book(book:  &Book)  {      print_title(&book);      print_chapters(&book);   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   }

Slide 100

Slide 100 text

✏️

Slide 101

Slide 101 text

Return this by 5pm on Friday and feel free to change it ✏️

Slide 102

Slide 102 text

Return this by 4:30pm on Friday but don't change it ✏️

Slide 103

Slide 103 text

✏️

Slide 104

Slide 104 text

✏️

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 107

Slide 107 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 108

Slide 108 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 109

Slide 109 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 110

Slide 110 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 111

Slide 111 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 112

Slide 112 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 113

Slide 113 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 114

Slide 114 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 115

Slide 115 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 116

Slide 116 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 117

Slide 117 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 118

Slide 118 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 119

Slide 119 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 120

Slide 120 text

fn  main()  {      let  mut  book  =  read_book("book1.txt");      print_book(&mut  book);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec,      bookmark:  u32
 }   fn  print_book(book:  &mut  Book)  {      print_title(&book);      print_chapters(&book);      book.bookmark  =  100;   }   fn  print_title(book:  &Book)  {      println!("Title:  {}",  book.title);   }   fn  print_chapters(book:  &Book)  {      let  len  =  book.chapters.len();      println!("Chapters:  {}",  len);   } Sub-Leasing

Slide 121

Slide 121 text

Rules of Borrowing • You can have many outstanding read-only borrows at once • A mutable borrow is unique: no other borrows, mutable
 or read-only, can occur at the same time

Slide 122

Slide 122 text

Rules of Borrowing • You can have many outstanding read-only borrows at once • A mutable borrow is unique: no other borrows, mutable
 or read-only, can occur at the same time • These rules are enforced by the compiler, not at runtime

Slide 123

Slide 123 text

Read-Only Borrows fn  main()  {      let  book1  =  read_book("book1.txt");      let  book2  =  read_book("book2.txt");      same(&book1,  &book2);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec   }   fn  same(a:  &Book,  b:  &Book)  -­‐>  bool  {      a.title  ==  b.title  &&      a.chapters  ==  b.chapters   }

Slide 124

Slide 124 text

Read-Only Borrows fn  main()  {      let  book1  =  read_book("book1.txt");      let  book2  =  read_book("book2.txt");      same(&book1,  &book2);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec   }   fn  same(a:  &Book,  b:  &Book)  -­‐>  bool  {      a.title  ==  b.title  &&      a.chapters  ==  b.chapters   } ✅

Slide 125

Slide 125 text

Two Read-Only Borrows fn  main()  {      let  book1  =  read_book("book1.txt");      same(&book1,  &book1);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec   }   fn  same(a:  &Book,  b:  &Book)  -­‐>  bool  {      a.title  ==  b.title  &&      a.chapters  ==  b.chapters   }

Slide 126

Slide 126 text

Two Read-Only Borrows fn  main()  {      let  book1  =  read_book("book1.txt");      same(&book1,  &book1);   }   pub  struct  Book  {
    title:  String,      chapters:  Vec   }   fn  same(a:  &Book,  b:  &Book)  -­‐>  bool  {      a.title  ==  b.title  &&      a.chapters  ==  b.chapters   } ✅

Slide 127

Slide 127 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book1  =  read_book("book1.txt");      let  mut  book2  =  read_book("book2.txt");      copy(&book1,  &mut  book2);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   }

Slide 128

Slide 128 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  book1  =  read_book("book1.txt");      let  mut  book2  =  read_book("book2.txt");      copy(&book1,  &mut  book2);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } ✅

Slide 129

Slide 129 text

pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } Mutable Borrows Must Be Unique

Slide 130

Slide 130 text

pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } Mutable Borrows Must Be Unique

Slide 131

Slide 131 text

pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } Mutable Borrows Must Be Unique ^~~~ error: cannot borrow `book` as mutable because it is also borrowed as immutable

Slide 132

Slide 132 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   }

Slide 133

Slide 133 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } ^~~~ note: previous borrow of `book` occurs here

Slide 134

Slide 134 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   }

Slide 135

Slide 135 text

Mutable Borrows Must Be Unique pub  struct  Book  {      title:  String,      chapters:  Vec   }   fn  main()  {      let  mut  book  =  read_book("book1.txt");      copy(&book,  &mut  book);   }   fn  copy(a:  &Book,  b:  &mut  Book)  {      b.title  =  a.title;   } ^ note: previous borrow ends here

Slide 136

Slide 136 text

Borrowing is the Secret Sauce

Slide 137

Slide 137 text

Closures

Slide 138

Slide 138 text

Closures fn  main()  {      println!("{:?}",  threes_squared(10));   }   fn  threes_squared(upto:  u32)  -­‐>  Vec  {      (0..upto)          .filter(|i|  i  %  3  ==  0)          .map(|i|  i.pow(2))          .collect()   }

Slide 139

Slide 139 text

Closed Over Variables fn  main()  {      println!("{:?}",  threes_squared(10,  "LOG"));   }   fn  threes_squared(upto:  u32,  string:  &str)  -­‐>  Vec  {      (0..upto)          .filter(|i|  i  %  3  ==  0)          .map(|i|  format!("{}:  {}",  string,  i.pow(2)))          .collect()   }

Slide 140

Slide 140 text

Equivalent Performance fn  main()  {      println!("{:?}",  threes_squared(10,  "LOG"));   }   fn  threes_squared(upto:  u32,  string:  &str)  -­‐>  Vec  {
    let  v  =  vec![];      loop  {
        if  i  %  3  ==  0  {              v.push(format!("{}:  {}",  string,  i  *  i));          }          if  i  <  upto  {  break;  }
    }      v   }

Slide 141

Slide 141 text

Details Abstracted fn  main()  {      println!("{:?}",  threes_squared(10,  "LOG"));   }   fn  threes_squared(upto:  u32,  string:  &str)  -­‐>  Vec  {
    let  v  =  Vec::with_capacity(upto  -­‐  1);      loop  {
        if  i  %  3  ==  0  {              v.push(format!("{}:  {}",  string,  i  *  i));          }          if  i  <  upto  {  break;  }
    }      v   }

Slide 142

Slide 142 text

Details Abstracted fn  main()  {      println!("{:?}",  threes_squared(10,  "LOG"));   }   fn  threes_squared(upto:  u32,  string:  &str)  -­‐>  Vec  {
    let  v  =  Vec::with_capacity(upto  -­‐  1);      loop  {
        if  i  %  3  ==  0  {              v.push(format!("{}:  {}",  string,  i  *  i));          }          if  i  <  upto  {  break;  }
    }      v   } Bounds Checks

Slide 143

Slide 143 text

Same Ownership Rules

Slide 144

Slide 144 text

FnOnce A closure that only runs once and can take ownership from its environment Fn A closure that cannot mutate its environment and can be shared across threads FnMut A closure that can mutate its environment but cannot be shared across threads

Slide 145

Slide 145 text

FnOnce fn  main()  {      let  buf  =  String::new();      stdin().read_line(&mut  buf).map(|size|  {
        println!("Read  {}  bytes",  size);          transfer(buf);
    });   }   fn  transfer(string:  String)  {      println!("Got  transferred  {:?}",  string);
 }

Slide 146

Slide 146 text

Unified Calling Syntax

Slide 147

Slide 147 text

Concurrency

Slide 148

Slide 148 text

"Shared Mutable State is the Root of All Evil"

Slide 149

Slide 149 text

No content

Slide 150

Slide 150 text

Channels Forbid Aliasing

Slide 151

Slide 151 text

Channels Forbid Aliasing Functional Forbid Mutation

Slide 152

Slide 152 text

Channels Forbid Aliasing Functional Forbid Mutation Rust Forbid Both at the Same Time

Slide 153

Slide 153 text

Rules of Borrowing • You can have many outstanding read-only borrows at once • A mutable borrow is unique: no other borrows, mutable
 or read-only, can occur at the same time

Slide 154

Slide 154 text

Rules of Borrowing • You can have many outstanding read-only borrows at once • A mutable borrow is unique: no other borrows, mutable
 or read-only, can occur at the same time • You can alias or mutate, but not both at the same time

Slide 155

Slide 155 text

Send Safe to transfer across threads (no borrowed values) Sync Safe to share across threads (no racy "interior mutability")

Slide 156

Slide 156 text

spawn() fn  main()  {      let  book  =  read_book("book1.txt");      spawn(||  {          println!("{}",  book);      });   }

Slide 157

Slide 157 text

spawn() fn  main()  {      let  book  =  read_book("book1.txt");      spawn(||  {          println!("{}",  book);      });   }

Slide 158

Slide 158 text

spawn() fn  main()  {      let  book  =  read_book("book1.txt");      spawn(||  {          println!("{}",  book);      });   } ^~~~ error: `book` does not live long enough

Slide 159

Slide 159 text

spawn() fn  main()  {      let  book  =  read_book("book1.txt");      spawn(move  ||  {          println!("{}",  book);      });   }

Slide 160

Slide 160 text

scoped() fn  main()  {      let  book  =  read_book("book1.txt");      let  guard  =  scoped(||  {          println!("{}",  book);      });
 
    //  do  other  work
 
    let  output  =  guard.join();   }

Slide 161

Slide 161 text

scoped() fn  main()  {      let  book  =  read_book("book1.txt");      let  guard  =  scoped(||  {          println!("{}",  book);      });
 
    //  do  other  work
 
    let  output  =  guard.join();  //  default  impl  of  Drop   }

Slide 162

Slide 162 text

High Level Productivity

Slide 163

Slide 163 text

OO

Slide 164

Slide 164 text

OO Syntax struct  Circle  {      x:  f64,      y:  f64,      radius:  f64,   }   impl  Circle  {      fn  area(&self)  -­‐>  f64  {          std::f64::consts::PI  *  (self.radius  *  self.radius)      }   }

Slide 165

Slide 165 text

Traits

Slide 166

Slide 166 text

Iterators

Slide 167

Slide 167 text

Enums with Methods

Slide 168

Slide 168 text

Operators

Slide 169

Slide 169 text

Thank You!

Slide 170

Slide 170 text

Questions? @wycats