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

Size: px
Start display at page:

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

Transcription

1

2

3 Useful Rust

4 $ cat ~/.profile GIT_AUTHOR_NAME=Florian Gilcher TWITTER_HANDLE=argorak GITHUB_HANDLE=skade BLOG=skade.me YAKS=yakshav.es

5 Backend Developer Ruby Programmer since 2003 Rust Programmer since 2013 CEO asquera GmbH

6 Community person Rust UG Berlin/Karlsruhe Search UG Berlin Ex-chairman of Ruby Berlin e.v.

7 Part of the global Rust community team Organiser eurucamp/jrubyconf.eu Organiser RustFest

8 Words of warning Rust is verbose......sometimes willfully obtuse......and rustc is the "Rust Complainer"

9 Rust is great, after the two to three weeks of pain in the beginning.

10 The compiler goes from annoying to your best friend.

11 The language

12 Systems programming language Developed by Mozilla Financed by Mozilla In Firefox!

13 Rust is little over a year old

14 Rust 1.0 is little over a year old

15 Rust itself is far older.

16 Properties C-like curly-braces language Java-like generics syntax expression based, similar to Ruby Rust is not object-oriented

17 Goals of Rust Memory-safety without garbage collection Support for concurrency and parallelism (Predictable) speed "Batteries replaceable"

18 Safety Static typesystem, with type inference No null pointers Unique pointers everywhere

19 Speed No hidden memory allocations Allocation-free core Predictable deallocations Abstractions without runtime overhead

20 Bells and whistles Easy and cost-free C FFI Regular releases (every 6 weeks) Great backwards-compatibility

21 Projects Servo, a web renderer in Rust Parity, an etherium implementation Rust Skylight, a Ruby app performance analyser rust-lang.org/friends.html

22 Solving tough problems

23 Shared mutable state is dangerous

24 Is sharing dangerous?

25 Is mutability dangerous?

26 Mutation of local values with one owner is not dangerous.

27 Sharing of immutable values is not dangerous.

28 Mutability and Sharing combined are dangerous.

29 Shared and mutable state is dangerous

30 Mutability fn main() { let int = 64; int = int + 1; //~^ ERROR re-assignment of immutable variable `a`

31 fn main() { let mut int = 64; int = int + 1;

32 Sharing struct Meal { name: String fn eat(m: Meal) { println!("ate: {", m.name);

33 let meal = Meal { name: String::from("Fish & Chips") ; for i in 1..3 { std::thread::spawn(move { eat(meal); //~^ ERROR capture of moved value: `meal` );

34 Ownership

35 Every value has (exactly) one owner.

36 The owner is responsible for cleanup.

37 The owner can mutate the value, if wanted.

38 Ownership can be passed.

39 fn eat(m: Meal) { println!("ate: {", m.name); // m will be destroyed here

40 fn eat(m: Meal) { println!("ate: {", m.name); drop(m)

41 fn eat(m: Meal) { let mut mutated = m; mutated.name = String::from("Godzilla & Chips"); println!("ate: {", mutated.name); drop(m)

42 This is also called "consuming".

43 I cannot consume a meal 3 times.

44 Borrowing

45 What you own, you can borrow.

46 fn describe_meal(m: &Meal) { println!("you handed me a: {", m.name);

47 fn mutate_meal(m: &mut Meal) { mutated_meal.name = String::from("Godzilla & Chips");

48 fn eat_borrowed_meal(m: &Meal) { eat(*m); //~^ ERROR cannot move out of borrowed content

49 You can borrow mutably once Or multiple times immutably Exclusive: mutable or immutable, never both Immutable borrows can never become mutable.

50 Shared and mutable state is dangerous

51 &mut T and &T are different types.

52 Traits trait Edible { fn eat(self); fn describe(&self);

53 impl Edible for Meal { fn eat(self) { println!("ate: {", self.name); fn describe(&self) { println!("this is: {", self.name);

54 fn main() { let meal = Meal { name: String::from("Fish & Chips") ; meal.describe(); meal.eat(); meal.eat(); //~^ ERROR use of moved value: `meal`

55 Generics fn eat_anything<f: Edible>(f: F) { f.eat();

56 fn eat_anything<f>(f: F) where F: Edible { f.eat();

57 Generic calls are monomorphised and have no runtime overhead.

58 struct Course<F: Edible> { items: Vec<F>

59 Items must be homogenous.

60 Errors and Results

61 We call algebraic datatypes "enums".

62 enum Option<T> { Some(T), None

63 enum Result<T, E> { Ok(T), Err(E)

64 Enough theory

65 Example: JSON

66 decode json_string :: Maybe MyData

67 Hey, describe me the data in the way we both know best, and I will derive the rest.

68 extern crate serde_json; // define MyApiMessage fn main() { use serde_json::from_str; let res = from_str::<myapimessage>("...");

69 Uses internal type information Fails early if the received message is unknown Does not raise exceptions

70 Who likes checked exceptions?

71 I do

72 fn main() { use serde_json::from_str; let res = from_str::<myapimessage>("..."); match res { Ok(message) =>..., Err(e) => println!("error: {", e)

73 Rust ships with a lot of machinery around converting errors, though...

74 pub trait From<T>: Sized { fn from(t) -> Self;

75 impl From<MyApiMessage> for MyDomainModel { fn from(t) -> Self { // here be alpaca

76 fn main() { use serde_json::from_str; let res = from_str::<myapimessage>("...").and_then( message { MyDomainModel::from(message) ) //~^ WARNING: unused result which must be used

77 Checking the complainer: compile-test

78 fn main() { use serde_json::from_str; let res = from_str::<myapimessage>("...").and_then( message { MyDomainModel::from(message) ) //~^ WARNING: unused result which must be used

79 It s not unusual for libraries to have test suites for the cases that should error/warn at complain time.

80 It s not unusual for libraries to have test suites for the cases that should error/warn at compile time.

81 Example: CouchDB replication

82 CouchDB Replication protocol

83 Describes the process to replicate a source database to a target database.

84 Replicator pub struct Replicator { source: String, target: String

85 fn main() { let r = Replicator { source: "source_name".into(), target: "target_name".into()

86 Inconvenient Initialisation depending on exact structure Struct fields are by default private, this is not going to work outside of the defining module.

87 Seperation of functions and state impl Replicator { pub fn new(s: String, t: String) -> Replicator { Replicator { source: s, target: t

88 fn main() { let r = Replicator::new( "source_name".into(), "target_name".into() );

89 This is still a bit inconvenient Can we get rid of the into() calls?

90 impl Replicator { pub fn new<s,t>(source: S, target: T) -> Replicator where S: Into<String>, T: Into<String> { Replicator { source: source.into(), target: target.into()

91 fn main() { let r = Replicator::new("source_name", "target_name");

92 The VerifyPeers steps Given a replicator between two databases: Check source existence Check target existence Create target if absent Done

93 Can we describe that in Rust?

94 Defining states pub struct Start; pub struct SourceExisting; pub struct TargetExisting; pub struct TargetAbsent; pub struct VerifiedPeers;

95 A stateful wrapper pub struct VerifyPeers<T> { replicator: Replicator, state: T

96 impl<s> VerifyPeers<S> { pub fn transition<x>(self, new_state: X) -> VerifyPeers<X> { VerifyPeers { replicator: self.replicator, state: new_state

97 let replicator = Replicator::new("source_name", "target_name"); let verification = VerifyPeers::new(replicator); let end = verification.transition(sourceexisting).transition(targetexisting).transition(verifiedpeers);

98 Safety gains

99 let replicator = Replicator::new("source_name", "target_name"); let verification = VerifyPeers::new(replicator); let end = verification.transition(sourceexisting).transition(targetexisting).transition(verifiedpeers); verification.transition(sourceexisting); //~^ ERROR use of moved value: `verification`

100 Obvious flaws

101 Nonsensical transitions struct Counter { count: i32 fn main() { let r = Replicator::new("source", "target"); let v = VerifyPeers::new(r); let counter = Counter { count: 0 ; let end = v.transition(counter);

102 Illegal transitions let end = verification.transition(verifiedpeers).transition(sourceexisting);

103 Marking states pub trait State { impl State for Start { impl State for SourceExisting { impl State for TargetExisting { impl State for TargetAbsent { impl State for VerifiedPeers {

104 Constraining to States impl<s: State> VerifyPeers<S> { pub fn transition<x>(self, new_state: X) -> VerifyPeers<X> where X: State { VerifyPeers { replicator: self.replicator, state: new_state

105 Now failing struct Counter { count: i32 fn main() { let r = Replicator::new("source", "target"); let v = VerifyPeers::new(r); let counter = Counter { count: 0 ; let end = v.transition(counter);

106 the trait bound Counter: statemachines::state is not satisfied

107 Constraining Transitions Rust conversion traits: From, TryFrom Into, TryInto Use is very common!

108 We can use them to model state transitions.

109 impl From<Start> for SourceExisting { fn from(_: Start) -> SourceExisting { SourceExisting

110 We implement in the same fashion: SourceExisting -> TargetAbsent SourceExisting -> TargetExisting TargetAbsent -> TargetExisting TargetExisting -> VerifiedPeers

111 impl<s: State> VerifyPeers<S> { pub fn transition<x>(self, new_state: X) -> VerifyPeers<X> where X: State + From<S> { VerifyPeers { replicator: self.replicator, state: new_state

112 Now failing fn main() { let r = Replicator::new("source", "target"); let v = VerifyPeers::new(r); let end = v.transition(verifiedpeers);

113 the trait bound statemachines::verifiedpeers: std::convert::from<statemachines::start> is not satisfied

114 I was promised Useful Rust and all I got was a lousy state machine!

115 How do we implement work? type Error = String;

116 impl VerifyPeers<Start> { pub fn check_source_existence(self) -> Result<VerifyPeers<SourceExisting>, Error> { if try!(check_source_existence()) { Ok(self.transition(SourceExisting)) else { Err("Source doesn t exist!".into())

117 Horray, we also got the failure state!

118 How do we implement a branch? pub enum TargetChecked { TargetExists(VerifyPeers<TargetExisting>), TargetAbsent(VerifyPeers<TargetAbsent>)

119 impl VerifyPeers<SourceExisting> { pub fn check_target_existence(self) -> Result<TargetChecked, Error> { if try!(target_exists()) { Ok(self.transition(TargetExisting)) else { Ok(self.transition(TargetAbsent))

120 extern crate statemachines; use statemachines::*; fn main() { let r = Replicator::new("source", "target"); let v = VerifyPeers::new(r); let end = v.check_source_existence().and_then( state { state.check_target_existence() ).and_then( state { //...

121 .and_then( state { match state { TargetChecked::TargetExists(s) => { s.finish() TargetChecked::TargetAbsent(s) => { try!(s.create_target()).finish() );

122 Free This abstraction is free!

123 Fully at compile-time Vanishes at runtime

124 A bit of low-level #[test] fn verify_peers_not_larger_then_replicator() { use std::mem::size_of; assert_eq!(size_of::<verifypeers<start>>(), size_of::<replicator>())

125 Final comments

126 We re exclusively using dynamic dispatch The whole state machine is on the stack

127 This pattern extends well and also works with, e.g. Futures instead of Results Other implementations are possible

128 Real-world: Laze RS Experimental CouchDB toolkit, see:

129 Conclusion Rust is sufficiently useful for patterns beyond the main focus to emerge.

130 Rust is focused on usability Usability is tough if you want finegrained control for the user In systems programming, usability is not champion

131 Interview If you have a Rust project, private or commercial, I d like to interview you.

132 twitter.com/argorak

133 rust-lang.org

134 Links

Rust for C++ Programmers

Rust for C++ Programmers Rust for C++ Programmers Vinzent Steinberg C++ User Group, FIAS April 29, 2015 1 / 27 Motivation C++ has a lot of problems C++ cannot be fixed (because of backwards compatibility) Rust to the rescue! 2

More information

Rust Advanced Topics

Rust Advanced Topics Rust Advanced Topics Adapted from https://skade.github.io/rust-three-dayscourse/presentation/toc/english.html Generic Functions 1. fn takes_anything(thing: T) -> T { 2. thing 3. } 4. fn main() { 5.

More information

Introduction to Rust. CC-BY Mozilla. Jonathan Pallant

Introduction to Rust. CC-BY Mozilla. Jonathan Pallant Introduction to Rust CC-BY Mozilla Jonathan Pallant 27 October 2016 What is Rust? Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety. www.rust-lang.org

More information

Advances in Programming Languages

Advances in Programming Languages Advances in Programming Languages Lecture 18: Concurrency and More in Rust Ian Stark School of Informatics The University of Edinburgh Friday 24 November 2016 Semester 1 Week 10 https://blog.inf.ed.ac.uk/apl16

More information

Guaranteeing memory safety in Rust

Guaranteeing memory safety in Rust Guaranteeing memory safety in Rust Nicholas D. Matsakis Mozilla Research 1 Hashtable in C / C++ template struct Hashtable { Bucket *buckets; unsigned num_buckets; template

More information

Next Gen Networking Infrastructure With Rust

Next Gen Networking Infrastructure With Rust Next Gen Networking Infrastructure With Rust Hi, I m @carllerche You may remember me from Most newer databases are written in a language that includes a runtime C / C++ Memory management we ll do it live

More information

Programming In Rust. Jim Blandy, / Portland, (Slides are as presented; followup discussion,

Programming In Rust. Jim Blandy, / Portland, (Slides are as presented; followup discussion, Programming In Rust Jim Blandy, Mozilla @jimblandy / Portland, 2015 (Slides are as presented; followup discussion, fixes, etc. on Reddit: http://goo.gl/thj2pw) 2 The set of Rust enthusiasts certainly seems

More information

Aaron Turon! Mozilla Research

Aaron Turon! Mozilla Research Aaron Turon Mozilla Research C/C++ ML/Haskell Rust Safe systems programming Why Mozilla? Browsers need control. Browsers need safety. Servo: Next-generation browser built in Rust. C++ What is control?

More information

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

Rust intro. (for Java Developers) JFokus #jfokus 1. 1 Rust intro (for Java Developers) JFokus 2017 - #jfokus 1. 1 Hi! Computer Engineer Programming Electronics Math

More information

1: /////////////// 2: // 1. Basics // 3: /////////////// 4: 5: // Functions. i32 is the type for 32-bit signed integers 6: fn add2(x: i32, y: i32) ->

1: /////////////// 2: // 1. Basics // 3: /////////////// 4: 5: // Functions. i32 is the type for 32-bit signed integers 6: fn add2(x: i32, y: i32) -> 1: /////////////// 2: // 1. Basics // 3: /////////////// 4: 5: // Functions. i32 is the type for 32-bit signed integers 6: fn add2(x: i32, y: i32) -> i32 { 7: // Implicit return (no semicolon) 8: x + y

More information

Rust: system programming with guarantees

Rust: system programming with guarantees Rust: system programming with guarantees CRI Monthly Seminar Arnaud Spiwack Pierre Guillou MINES ParisTech, PSL Research University Fontainebleau, July 6th, 2015 1 / 29 High level programming languages

More information

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

CMSC 330: Organization of Programming Languages. Ownership, References, and Lifetimes in Rust CMSC 330: Organization of Programming Languages Ownership, References, and Lifetimes in Rust CMSC330 Spring 2018 1 Memory: the Stack and the Heap The stack constant-time, automatic (de)allocation Data

More information

The Case for Building a Kernel

The Case for Building a Kernel The Case for Building a Kernel in Rust Amit Levy Brad Campbell Branden Ghena Pat Pannuto Philip Levis Prabal Dutta Stanford University & University of Michigan September 2nd 2017 Memory and type safety

More information

Why you should take a look at

Why you should take a look at Why you should take a look at Antonin Carette - FOSDEM 2018 - Rust devroom Slides and resources available @ github.com/k0pernicus/fosdem_rust_talk 1 Chalut 'tiot biloute! I tried to understand what the

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Smart Pointers in Rust CMSC330 Spring 2018 Copyright 2018 Michael Hicks, the University of Maryland. Some material based on https://doc.rustlang.org/book/second-edition/index.html

More information

Introduction to Rust 2 / 101

Introduction to Rust 2 / 101 1 / 101 Introduction to Rust 2 / 101 Goal Have a good chance of being able to read and understand some Rust code. 3 / 101 Agenda 1. What's not that unique about Rust 2. What makes Rust somewhat unique

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Structs and Enums in Rust CMSC330 Spring 2018 Copyright 2018 Niki Vazou, the University of Maryland. Some material based on https://doc.rustlang.org/book/second-edition/index.html

More information

Rust. A new systems programming language. 1.0 was released on May 15th. been in development 5+ years. releases every 6 weeks

Rust. A new systems programming language. 1.0 was released on May 15th. been in development 5+ years. releases every 6 weeks 1 Rust A new systems programming language 1.0 was released on May 15th been in development 5+ years releases every 6 weeks Pursuing the trifecta: safe, concurrent, fast Gone through many radical iterations

More information

Rust for high level applications. Lise Henry

Rust for high level applications. Lise Henry 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

More information

Next Gen Networking Infrastructure With Rust

Next Gen Networking Infrastructure With Rust Next Gen Networking Infrastructure With Rust Hi, I m @carllerche Let s write a database! Most newer databases are written in a language that includes a runtime. C / C++ Memory management we ll do it live

More information

CMSC 330: Organization of Programming Languages. Rust Basics

CMSC 330: Organization of Programming Languages. Rust Basics CMSC 330: Organization of Programming Languages Rust Basics CMSC330 Spring 2018 1 Organization It turns out that a lot of Rust has direct analogues in OCaml So we will introduce its elements with comparisons

More information

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

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Closures and Iterators In Rust CMSC330 Spring 2018 Copyright 2018 Michael Hicks, the University of Maryland. Some material based on https://doc.rustlang.org/book/second-edition/index.html

More information

Region-based Memory Management. Advanced Operating Systems Lecture 10

Region-based Memory Management. Advanced Operating Systems Lecture 10 Region-based Memory Management Advanced Operating Systems Lecture 10 Lecture Outline Rationale Stack-based memory management Region-based memory management Ownership Borrowing Benefits and limitations

More information

Nicholas Matsakis! Mozilla Research

Nicholas Matsakis! Mozilla Research Nicholas Matsakis! Mozilla Research Parallel! Systems programming without the hassle crashes! heisenbugs! fear 2 C/C++: efficiency first! destructors memory layout smart pointers monomorphization Research

More information

PyCon Otto 6-9 April 2017 Florence. Rusty Python. Rust, a new language for our programmer tool belt. Matteo

PyCon Otto 6-9 April 2017 Florence. Rusty Python. Rust, a new language for our programmer tool belt. Matteo PyCon Otto 6-9 April 2017 Florence Rusty Python Rust, a new language for our programmer tool belt Matteo Bertini @naufraghi 1 Rust Born as a personal project started in 2006 by Mozilla employee Graydon

More information

Separate Compilation Model

Separate Compilation Model Separate Compilation Model Recall: For a function call to compile, either the function s definition or declaration must appear previously in the same file. Goal: Compile only modules affected by recent

More information

Corrections made in this version not in first posting:

Corrections made in this version not in first posting: 1 Changelog 1 Corrections made in this version not in first posting: 12 April 2017: slide 15: correct arrow from B-freed to D-freed 12 April 2017: slide 42: correct phrasing on what is borrowed fuzzing

More information

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

Rust. A safe, concurrent, practical language. Graydon Hoare October 2012 Rust A safe, concurrent, practical language Graydon Hoare October 2012 This is not a marketing talk Purpose: Convince you there's something interesting here Provide some technical

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

September 10,

September 10, September 10, 2013 1 Bjarne Stroustrup, AT&T Bell Labs, early 80s cfront original C++ to C translator Difficult to debug Potentially inefficient Many native compilers exist today C++ is mostly upward compatible

More information

MY GOOD FRIEND RUST. Matthias Endler trivago

MY GOOD FRIEND RUST. Matthias Endler trivago MY GOOD FRIEND RUST Matthias Endler trivago How to write the word Mississippi? How to write the word Mississippi? Mississippi Sebastian is stupid. Oh please tell me more about Matthias Endler! } Düsseldorf,

More information

RustBelt: Securing the Foundations of the Rust Programming Language

RustBelt: Securing the Foundations of the Rust Programming Language RustBelt: Securing the Foundations of the Rust Programming Language Ralf Jung, Jacques-Henri Jourdan, Robbert Krebbers, Derek Dreyer POPL 2018 in Los Angeles, USA Max Planck Institute for Software Systems

More information

Advances in Programming Languages: Regions

Advances in Programming Languages: Regions Advances in Programming Languages: Regions Allan Clark and Stephen Gilmore The University of Edinburgh February 22, 2007 Introduction The design decision that memory will be managed on a per-language basis

More information

The Concept of Ownership in Rust and Swift

The Concept of Ownership in Rust and Swift The Concept of Ownership in Rust and Swift The Concept of Ownership in Rust and Swift By Elaf A Alhazmi, M.Sc. A Thesis Submitted to The Department of Computing and Software and the School of Graduate

More information

Tokio: How we hit 88mph. Alex Crichton

Tokio: How we hit 88mph. Alex Crichton Tokio: How we hit 88mph Alex Crichton Tokio: How we hit 142km/h Alex Crichton Mio is low level Tokio Zero-cost futures trait Future Lightweight tasks A L E X S T O K I O RUST 2016 2018 MIO, FUTURES,

More information

Let s Rust in Samba. Trying to use Samba with Rust libraries. Kai Blin Samba Team. SambaXP

Let s Rust in Samba. Trying to use Samba with Rust libraries. Kai Blin Samba Team. SambaXP Let s Rust in Samba Trying to use Samba with Rust libraries Kai Blin Samba Team SambaXP 2018 2017-06-06 Intro M.Sc. in Computational Biology Ph.D. in Microbiology Samba Team member 2/42 Overview Rust Intro

More information

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

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Structure of Programming Languages Lecture 10

Structure of Programming Languages Lecture 10 Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,

More information

CS527 Software Security

CS527 Software Security Security Policies Purdue University, Spring 2018 Security Policies A policy is a deliberate system of principles to guide decisions and achieve rational outcomes. A policy is a statement of intent, and

More information

Winter Compiler Construction Who. Mailing list and forum

Winter Compiler Construction Who. Mailing list and forum Winter 2006-2007 Compiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv University Who Roman Manevich Schreiber Open-space (basement) Tel: 640-5358 rumster@post.tau.ac.il

More information

Name, Scope, and Binding. Outline [1]

Name, Scope, and Binding. Outline [1] Name, Scope, and Binding In Text: Chapter 3 Outline [1] Variable Binding Storage bindings and lifetime Type bindings Type Checking Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur 2

More information

1. Compile Time Error:

1. Compile Time Error: 1. Compile Time Error: A successful compilation simply returns silently. Hence your aim should be that your program is so agreeable with the compiler that the compiler happily returns silently. If you

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Programming refresher and intro to C programming

Programming refresher and intro to C programming Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2

More information

The Case for N-Body Simulations in Rust

The Case for N-Body Simulations in Rust Int'l Conf. Scientific Computing CSC'16 3 The Case for N-Body Simulations in Rust A. Hansen, M. C. Lewis Department of Computer Science, Trinity University, San Antonio, Texas, United States Abstract In

More information

QUIZ Friends class Y;

QUIZ Friends class Y; QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They

More information

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from

More information

Implementing Abstractions

Implementing Abstractions Implementing Abstractions Pointers A pointer is a C++ variable that stores the address of an object. Given a pointer to an object, we can get back the original object. Can then read the object's value.

More information

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS Pages 792 to 800 Anna Rakitianskaia, University of Pretoria INITIALISING POINTER VARIABLES Pointer variables are declared by putting

More information

Adding Lifetime Checking to Chapel Michael Ferguson, Cray Inc. CHIUW 2018 May 25, 2018

Adding Lifetime Checking to Chapel Michael Ferguson, Cray Inc. CHIUW 2018 May 25, 2018 Adding Lifetime Checking to Chapel Michael Ferguson, Cray Inc. CHIUW 2018 May 25, 2018 Safe Harbor Statement This presentation may contain forward-looking statements that are based on our current expectations.

More information

CSE341: Programming Languages Lecture 11 Type Inference. Dan Grossman Spring 2016

CSE341: Programming Languages Lecture 11 Type Inference. Dan Grossman Spring 2016 CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Spring 2016 Type-checking (Static) type-checking can reject a program before it runs to prevent the possibility of some errors A feature

More information

Introduction To C#.NET

Introduction To C#.NET Introduction To C#.NET Microsoft.Net was formerly known as Next Generation Windows Services(NGWS).It is a completely new platform for developing the next generation of windows/web applications. However

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables

More information

Stanford University Computer Science Department CS 295 midterm. May 14, (45 points) (30 points) total

Stanford University Computer Science Department CS 295 midterm. May 14, (45 points) (30 points) total Stanford University Computer Science Department CS 295 midterm May 14, 2008 This is an open-book exam. You have 75 minutes. Write all of your answers directly on the paper. Make your answers as concise

More information

Memory Leak. C++: Memory Problems. Memory Leak. Memory Leak. Pointer Ownership. Memory Leak

Memory Leak. C++: Memory Problems. Memory Leak. Memory Leak. Pointer Ownership. Memory Leak Memory Leak C++ Memory Problems or When Good Memory Goes Bad A bug in a program that prevents it from freeing up memory that it no longer needs. As a result, the program grabs more and more memory until

More information

Parallel Programming in Distributed Systems Or Distributed Systems in Parallel Programming

Parallel Programming in Distributed Systems Or Distributed Systems in Parallel Programming Parallel Programming in Distributed Systems Or Distributed Systems in Parallel Programming Philippas Tsigas Chalmers University of Technology Computer Science and Engineering Department Philippas Tsigas

More information

Threads Chapter 5 1 Chapter 5

Threads Chapter 5 1 Chapter 5 Threads Chapter 5 1 Chapter 5 Process Characteristics Concept of Process has two facets. A Process is: A Unit of resource ownership: a virtual address space for the process image control of some resources

More information

Amit Levy SITP Retreat, June 22, Tock: A Secure Operating System for Microcontrollers

Amit Levy SITP Retreat, June 22, Tock: A Secure Operating System for Microcontrollers Amit Levy SITP Retreat, June 22, 2018 Tock: A Secure Operating System for Microcontrollers Limitations of Microcontroller Sofware Low memory: ~64 kb RAM No virtual memory Can t use Linux! No isolation

More information

TESTING IN RUST. A PRIMER IN TESTING AND FOSDEM 2018

TESTING IN RUST. A PRIMER IN TESTING AND FOSDEM 2018 TESTING IN RUST A PRIMER IN TESTING AND MOCKING @donald_whyte FOSDEM 2018 ABOUT ME So ware Engineer @ Engineers Gate Real-time trading systems Scalable data infrastructure Python/C++/Rust developer MOTIVATION

More information

Kakadu and Java. David Taubman, UNSW June 3, 2003

Kakadu and Java. David Taubman, UNSW June 3, 2003 Kakadu and Java David Taubman, UNSW June 3, 2003 1 Brief Summary The Kakadu software framework is implemented in C++ using a fairly rigorous object oriented design strategy. All classes which are intended

More information

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1 CSE 401 Compilers Static Semantics Hal Perkins Winter 2009 2/3/2009 2002-09 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Symbol tables General ideas for now; details later for MiniJava project

More information

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

More information

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

CMSC 330: Organization of Programming Languages. Functional Programming with Lists CMSC 330: Organization of Programming Languages Functional Programming with Lists 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as a linked data structure

More information

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

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Self-checking software insert specifications about the intent of a system

Self-checking software insert specifications about the intent of a system Assertions Reading assignment A. J. Offutt, A Practical System for Mutation Testing: Help for the Common Programmer, Proceedings of the 12th International Conference on Testing Computer Software, Washington,

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

Garbage Collection (1)

Garbage Collection (1) Coming up: Today: Finish unit 6 (garbage collection) start ArrayList and other library objects Wednesday: Complete ArrayList, basics of error handling Friday complete error handling Next week: Recursion

More information

MY PYTHON IS RUSTING. A PYTHON AND RUST LOVE STORY Ronacher

MY PYTHON IS RUSTING. A PYTHON AND RUST LOVE STORY Ronacher MY PYTHON IS RUSTING A PYTHON AND RUST LOVE STORY Armin @mitsuhiko Ronacher and here is where you can find me twitter.com/@mitsuhiko github.com/mitsuhiko lucumr.pocoo.org/ so I heard you are doing Rust

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.. COMP6771 Advanced C++ Programming Week 5 Part Two: Dynamic Memory Management 2016 www.cse.unsw.edu.au/ cs6771 2.. Revisited 1 #include 2 3 struct X { 4 X() { std::cout

More information

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

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file? QUIZ on Ch.5 Why is it sometimes not a good idea to place the private part of the interface in a header file? Example projects where we don t want the implementation visible to the client programmer: The

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:

More information

Memory Management and Efficient Graph Processing in Rust

Memory Management and Efficient Graph Processing in Rust Memory Management and Efficient Graph Processing in Rust KEVIN CHEN and ELBERT LIN Stanford University 1. INTRODUCTION Graphs are a common data structure in most object-oriented programming languages due

More information

Dynamic Memory: Alignment and Fragmentation

Dynamic Memory: Alignment and Fragmentation Dynamic Memory: Alignment and Fragmentation Learning Objectives Explain the purpose of dynamic memory Define the terms arena, heap Identify common errors involving dynamic memory Explain how dynamic memory

More information

Haskell in the Software Industry

Haskell in the Software Industry Haskell in the Software Industry What is Haskell? Haskell in a nutshell Haskell is a pure, non-strict, statically typed, garbage collected, general purpose, functional programming language. Early history

More information

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont. CMSC 330: Organization of Programming Languages OCaml 1 Functional Programming Dialects of ML ML (Meta Language) Univ. of Edinburgh,1973 Part of a theorem proving system LCF The Logic of Computable Functions

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Think like an Elm developer

Think like an Elm developer Think like an Elm developer Piper Niehaus Denver, CO, USA Backpacker / skier Nonprofit board chair Software Engineer at Pivotal Pivotal Tracker team Elm in Production since 2016 Internal Products and Services

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

CMSC 330: Organization of Programming Languages. Strings, Slices, Vectors, HashMaps in Rust

CMSC 330: Organization of Programming Languages. Strings, Slices, Vectors, HashMaps in Rust CMSC 330: Organization of Programming Languages Strings, Slices, Vectors, HashMaps in Rust CMSC330 Spring 2018 1 String Representation Rust s String is a 3-tuple A pointer to a byte array (interpreted

More information

G52CPP C++ Programming Lecture 9

G52CPP C++ Programming Lecture 9 G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And

More information

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

G52CPP C++ Programming Lecture 7. Dr Jason Atkin G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A

More information

Static Analysis of Embedded C

Static Analysis of Embedded C Static Analysis of Embedded C John Regehr University of Utah Joint work with Nathan Cooprider Motivating Platform: TinyOS Embedded software for wireless sensor network nodes Has lots of SW components for

More information

Functional Programming in Java. CSE 219 Department of Computer Science, Stony Brook University

Functional Programming in Java. CSE 219 Department of Computer Science, Stony Brook University Functional Programming in Java CSE 219, Stony Brook University What is functional programming? There is no single precise definition of functional programming (FP) We should think of it as a programming

More information

How Rust is Tilde s Competitive Advantage

How Rust is Tilde s Competitive Advantage Jan. 2018 Rust Case Study: How Rust is Tilde s Competitive Advantage The analytics startup innovates safely with the help of Rust Copyright 2018 The Rust Project Developers All rights reserved graphics

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Mutation. COS 326 Andrew W. Appel Princeton University. slides copyright David Walker and Andrew W. Appel

Mutation. COS 326 Andrew W. Appel Princeton University. slides copyright David Walker and Andrew W. Appel Mutation COS 326 Andrew W. Appel Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel Mutation? 2 Reasoning about Mutable State is Hard mutable set insert i s1; f x; member

More information

Pointers. Developed By Ms. K.M.Sanghavi

Pointers. Developed By Ms. K.M.Sanghavi Pointers Developed By Ms. K.M.Sanghavi Memory Management : Dynamic Pointers Linked List Example Smart Pointers Auto Pointer Unique Pointer Shared Pointer Weak Pointer Memory Management In order to create

More information

Haskell in the corporate environment. Jeff Polakow October 17, 2008

Haskell in the corporate environment. Jeff Polakow October 17, 2008 Haskell in the corporate environment Jeff Polakow October 17, 2008 Talk Overview Haskell and functional programming System description Haskell in the corporate environment Functional Programming in Industry

More information

WebAssembly. neither Web nor Assembly, but Revolutionary

WebAssembly. neither Web nor Assembly, but Revolutionary WebAssembly neither Web nor Assembly, but Revolutionary The WebAssembly revolution has begun Jay Phelps Chief Software Architect previously Support, Dev Rel, Staff Augmentation, Mentorship, and more www.thisdot.co

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Winter 2009 Lecture 7 Introduction to C: The C-Level of Abstraction CSE 303 Winter 2009, Lecture 7 1 Welcome to C Compared to Java, in rough

More information

How Rust views tradeoffs. Steve Klabnik

How Rust views tradeoffs. Steve Klabnik How Rust views tradeoffs Steve Klabnik 03.04.2019 What is a tradeoff? Bending the Curve Overview Design is about values Case Studies BDFL vs Design By Committee Stability Without Stagnation Acceptable

More information

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list.

A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list. A linear-list Data Structure where - addition of elements to and - removal of elements from are restricted to the first element of the list. the first element of the list a new element to (the Top of)

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Smart Pointers and Constness Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de Summer

More information

C Programming Review CSC 4320/6320

C Programming Review CSC 4320/6320 C Programming Review CSC 4320/6320 Overview Introduction C program Structure Keywords & C Types Input & Output Arrays Functions Pointers Structures LinkedList Dynamic Memory Allocation Macro Compile &

More information