How Rust Makes Advanced Type Systems Accessible to the Masses

Talk Outline

  • Dynamically-typed and Interpreted Languages
  • Type systems
  • Rust

 

Link to slides:

https://goo.gl/tSoLUS

These pictures are from 8-9 years ago!

Python

  • Great for learning and teaching
  • Online resources, tutorials, books
  • English-like syntax with "and", "or", and "not" which is readable for people with little or no programming background
  • Big ecosystem of libraries and many production users
import random
min = 1
max = 6

roll_again = "yes"

while roll_again == "yes":
    print "Rolling the dices..."
    print "The values are...."
    print random.randint(min, max)
    print random.randint(min, max)

    roll_again = raw_input("Again? ")

if (roll_again.startswith("never") and
    roll_again.endswith("ever")):

    print "I didn't want to play anyway."

elif not (roll_again.startswith("no") or
    roll_again.startswith("No")):

    print "That wasn't an option!"

Python

Interpreted

print "Favourite Animal Test"

prompt = "What is your favourite animal?"
fav = raw_input(prompt)

response = "That is a "
if fav == "dog":
    response += "great"

elif fav == "cat":
    response += "cool"

elif fav == "dragon":
    response += "unreal"

else:
    response += "awesome"

response += " choice!"
print response
 32 + "abc"

Dynamically Typed

This isn't valid

The Python interpreter evaluates programs line by line

# This will produce some text
ans = raw_input("Pick some letters: ")
# This will produce an integer
ans2 = int(raw_input("Pick some numbers: "))

# You can't add text to an integer, but
# Python will still run the above code
# before failing on this next line
print ans + ans2
# Dynamically typed also means that
# you can do something like this:
stuff = "abc"
stuff = 22

# stuff can be anything you want and
# the Python interpreter will only
# check it when you use it

Types

Types and type systems are a way to provide more information about your code to a program that can check your code automatically.

Program with Types

Type Checker

User

Feedback

Program

Types

You don't need types!

  • A human can check pretty much everything that a type checker could check for you
  • The question is: Why should we?
  • It is easy for computers to check a lot of these details for us
  • We just have to give them enough information to do that
  • Why spend your time doing something you can automate away?

Dynamically Typed

  • Python
  • Ruby
  • JavaScript
  • Racket/Lisp
  • Lua
  • PHP
  • and many more!

Statically Typed

  • C, C++, C#
  • Java
  • Rust
  • Haskell
  • Scala
  • Swift
  • and many more!

Types are checked while the program is running

Types are checked before the program can run

Rust

  • Rust is a statically typed, compiled language
  • In development since 2006, stable 1.0 version released in 2015
  • Most loved programming language in the StackOverflow developer survey two years in a row in 2016 and 2017
  • Fantastic community full of kind, compassionate and very knowledgeable people
  • Lots of great learning resources, thorough documentation, and people who are happy to answer your questions

Rust

  • Review: Types and type systems are a way to provide more information that can be checked beforehand
  • Rust checks for trivial errors like passing the wrong types to a function or using incompatible types with an operator
  • Programs that type check are guaranteed to be memory safe and not have any data races
  • You can write code that will not type check unless it is correct

Rust

  • The speed of C and C++, memory safety of Java, and the expressiveness of Haskell
  • Clean and relatively simple syntax that lets you focus on what you want to do and not need to write a lot of extra code to do it
  • From the FAQ: "We do not employ any particularly cutting-edge technologies. Old, established techniques are better."

Friends of Rust
https://www.rust-lang.org/en-US/friends.html

Takeaways

  • Rust makes advanced type systems accessible to everyone by having a great community, a fantastic set of features, and excellent learning resources
  • Type systems are good, important parts of programming languages that will reduce the amount of problems in your code
  • We should be using advanced type systems so that we can give the computers checking our code as much information as possible

 

Learn Rust

  • Learn Rust from scratch by drawing pictures
  • No prior programming experience required
  • Ready in a few weeks!

Turtle

Website: turtle.rs

Thank you!

Made with Slides.com