Rust for high level applications. Lise Henry

Similar documents
CMSC 330: Organization of Programming Languages. Ownership, References, and Lifetimes in Rust

QUIZ. What is wrong with this code that uses default arguments?

Advances in Programming Languages

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Rust for C++ Programmers

Rust intro. (for Java Developers) JFokus #jfokus 1. 1

CS558 Programming Languages

The compiler is spewing error messages.

How Rust views tradeoffs. Steve Klabnik

CS558 Programming Languages


D Programming Language

3 Continuous Integration 3. Automated system finding bugs is better than people

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CS558 Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Introduction to Rust. CC-BY Mozilla. Jonathan Pallant

Software Design and Analysis for Engineers

The Case for Building a Kernel

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

QUIZ Friends class Y;

CS 370 The Pseudocode Programming Process D R. M I C H A E L J. R E A L E F A L L

Lecture Concurrency versus parallelism Shared memory versus messages DSM. CMPSCI 377 Operating Systems Fall 2009

Rust: system programming with guarantees

Chrome if I want to. What that should do, is have my specifications run against four different instances of Chrome, in parallel.

CSE332: Data Abstractions Lecture 23: Programming with Locks and Critical Sections. Tyler Robison Summer 2010

A Sophomoric Introduction to Shared-Memory Parallelism and Concurrency Lecture 5 Programming with Locks and Critical Sections

Programming Languages

COMP 410 Lecture 1. Kyle Dewey

Aaron Turon! Mozilla Research

RustBelt: Securing the Foundations of the Rust Programming Language

Next: What s in a name? Programming Languages. Data model in functional PL. What s in a name? CSE 130 : Fall Lecture 13: What s in a Name?

PyPy - How to not write Virtual Machines for Dynamic Languages

Better Stories, Better Languages

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Microservices Smaller is Better? Eberhard Wolff Freelance consultant & trainer

PROBLEM SOLVING 11. July 24, 2012

The fringe of a binary tree are the values in left-to-right order. For example, the fringe of the following tree:

CIS 45, The Introduction. What is a database? What is data? What is information?

Mutable Data Types. Prof. Clarkson Fall A New Despair Mutability Strikes Back Return of Imperative Programming

Rust Advanced Topics

Stop coding Pascal. Saturday, April 6, 13

Chapter 5. Names, Bindings, and Scopes

Chamberlin and Boyce - SEQUEL: A Structured English Query Language

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Abram Hindle Kitchener Waterloo Perl Monger October 19, 2006

Swift, functional programming, and does it matter? Alexis

Basic Keywords Practice Session

Swift by Practical Example. Justin Miller

Frege. purely functional programming on the JVM. JUG Luzern 2016

CMSC 330: Organization of Programming Languages

Nicholas Matsakis! Mozilla Research

It turns out that races can be eliminated without sacrificing much in terms of performance or expressive power.

Writing Code and Programming Microcontrollers

MySQL. The Right Database for GIS Sometimes

Low level security. Andrew Ruef

COMP390 (Design &) Implementation

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Rust. A safe, concurrent, practical language. Graydon Hoare October 2012

Guaranteeing memory safety in Rust

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

CISC-124. Casting. // this would fail because we can t assign a double value to an int // variable

CS252 Advanced Programming Language Principles. Prof. Tom Austin San José State University Fall 2013

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Programming Languages. Streams Wrapup, Memoization, Type Systems, and Some Monty Python

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Overview. Rationale Division of labour between script and C++ Choice of language(s) Interfacing to C++ Performance, memory

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Errors and Exceptions

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

CS 3 Introduction to Software Engineering. 3: Exceptions

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

Overview. Why Pointers?

Next Gen Networking Infrastructure With Rust

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Files and Streams

Frege. purely functional programming on the JVM. GOTO Berlin 2015

Chapter Goals. Contents LOOPS

CSE341: Programming Languages Lecture 26 Course Victory Lap. Dan Grossman Spring 2016

CS11 Advanced C++ Fall Lecture 7

The Case for N-Body Simulations in Rust

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

Introduction to Nate Foster Spring 2018

Writing Cognitive Swift Apps developerworks Open Tech Talk March 8, 2017

CSE373: Data Structure & Algorithms Lecture 23: Programming Languages. Aaron Bauer Winter 2014

Think like an Elm developer

Welcome to Python! If you re the type of person who wants to know

Deep C (and C++) by Olve Maudal

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

CS 241 Honors Memory

The Dynamic Typing Interlude

Makefile Tutorial. Eric S. Missimer. December 6, 2013

Introduction to Programming Style

$ cat ~/.profile GIT_AUTHOR_NAME=Florian Gilcher TWITTER_HANDLE=argorak GITHUB_HANDLE=skade BLOG=skade.

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Transcription:

Rust for high level applications Lise Henry

Who am I Elisabeth Henry A.k.a Lizzie Crowdagger Computer science background Semi-professional fantasy writer I like Rust, but not really into systems programming Crowbook A bad choice to use Rust for this?

High-level applications CLI apps, GUI apps, small games, Performance is not that important Safety is not really a concern No need for low-level stuff Comparison: Java, Python, Ruby,

Rust Systems programming Blazingly fast Prevents segfault Safety Comparison: C/C++

Doesn t seem like a good fit error[e0499]: cannot borrow `v` as mutable more than once at a time --in> test_mut.rs:5:13 3 for x in &mut v { - first mutable borrow occurs here 4 if *x % 2 == 0 { 5 v.push(*x + 1); ^ second mutable borrow occurs here 6 } 7 } - first borrow ends here error: aborting due to previous error

Rust is painful

Past experiences with programming Disclaimer: I am not a great programmer Lazy Not great designer Not enough checks and tests Easy way instead of the right way Portfolio of abandoned projects as soon as they grow a bit

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Past experiences with programming

Imperative programming Many languages make it easy to start coding But also to do things the wrong way Complexity Hard to reason about Solutions: Good programmers don t to that It s because you have a bad design

Hiding complexity Lots of easy-to-learn languages hide a lot of complexity But that doesn t always make things simpler in the long term a = [1, 2, 3] b = a b.append(4) print a A bit like hiding pain but ignoring pain isn t always a great idea

Rust goes a long way to make sure you brush your teeth Lots of checks at compile time Type system Enums Traits Libraries can leverage all this Make sure you do the right thing

Experience with Rust

Experience with Rust

Experience with Rust

Experience with Rust

Experience with Rust

Experience with Rust

What s unique about Rust? The (dreaded) borrow checker Great for having this low overhead But for high-level applications What if we defaulted to using Arc<RefCell<T>> everywhere? Rust as OCaml with different syntax? Is Rust be ok-ish for high-level despite the borrow checker? Or could the borrow checker be actually, you know, good for that too?

The dreaded borrow checker A reference can be shared mutable pick one Memory safety! Prevents data races!

The dreaded borrow checker A reference can be shared mutable pick one Memory safety! Prevents data races! Readable code?

Example print a foo() bar.foo() print a # Can be different! Hard to reason locally Have to know the details of every function/method Spaghetti!

Example in Rust let a = some_stuff(); println!("{:?}", a); foo(); bar.foo(); println!("{:?}", a); // Is the same!

Example in Rust (bis) let a = some_stuff(); println!("{:?}", a); foo(&mut a); { let bar = &mut a; bar.foo(); } println!("{:?}", a); // Has changed

The dreaded borrow checker Ensures that If you re using something, no-one interferes with it Unless it s explicit If you modify something you haven t meddled where you shouldn t have Makes it easier to reason about code Helps with safety and data races But also with correctness, maintenance,

Personal again Two kind of borrow checker issues Easy to fix, but annoying ones vec.push(vec.len()) Hard ones where you have to step back and think about your design Having to refactor is painful and time-consuming But it avoid later problems that can be more painful and time consuming If you really have to get around it (Cell, Mutex, not event talking about unsafe), you really should know what you are doing

Alternative: functional programming No mix between sharing and mutability No mutability at all! Simple to reason about the code Except you have to get used to it Have to rewire your brain somehow

Monads

Position in the landscape of PL Imperative programming Alias and mutation openbar Garbage collection mitigats the problem but doesn t solve it Functional programming Rust No mutation at all Controlled mutability Not just interesting for systems programming Provides another alternative

In summary Short-term VS long-term Rust can be hard at first, but it makes things easier later on Bugs Maintenance Accepting contributions Problem: you might not see the time you gain Since you don t have to spend days finding the bugs The compiler is grumpy for you so you don t have to be

Rust For beginner programmers? Probably not ideal You have to learn quite a few things I hope I m wrong :) For great programmers? Not needed For average programmers? Who might not have the best design at first try Who might forget some things sometimes Who might sometimes be lazy Basically, mere mortals Makes thing easier in the long run

What can be improved?

Language Borrow checking is necessary but can be refined Non-lexical lifetimes Nested method calls Some * could be removed Match Auto-deref for generic functions/methods &*(?!) Object-oriented Delegate implementation Specialisation

Ecosystem YMMV, but younger than Java s, C#, Python s, Ruby s, Personnal list Internationalisation Lack of guidelines for writing applications Some kind of crates.io-like platform where you can publish the code of an app and it Builds it Cross-compiles it Packages it to.deb/rpm/whatever

Community Welcoming community Increasing Rust s reach Rustbridge

Thanks! Questions? Twitter: @lise henry (or @crowdagger if you can bear french and flood) Github: lise-henry