![Page 1: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/1.jpg)
Today, you have been hearing about all sorts of clever new languages, language features, and uses of
language features …
And now for something completely different …
![Page 2: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/2.jpg)
Now, we are going to tell you about a boring language with no new language features, or uses of language
features …
And now for something completely different …
![Page 3: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/3.jpg)
Grace A New Educational
Object-O!ented Programming
Langua"
James Noble
Andrew Black
Kim Bruce
3
![Page 4: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/4.jpg)
Suppose:
You are going to teach object-oriented programming to 1st year students.
What language would you choose?
4
![Page 5: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/5.jpg)
Which language?
ECOOP 2010: we don't like the available options
“Professional” languages too complex for teaching (Scala, C#, Java …)
Smalltalk doesn't support static typing; Python has inconsistent method syntax, no encapsulation
Group decision: design a modern object-oriented language specifically for teaching
5
![Page 6: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/6.jpg)
High Level Goal"A Haskell for OO"
Integrate proven newer ideas in programming languages into a simple language for teaching
language features represent key concepts cleanly
allow students to focus on the essential, rather than accidental, complexities of programming and modelling.
6
![Page 7: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/7.jpg)
ObjectivesLow overhead for simple programs
Good IDE support for novices
Simple semantic model
Support a variety of approaches to teaching
Objects-first and objects-late
Untyped, Typeful and Gradually-typed
Easy transition to other languages
7
![Page 8: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/8.jpg)
Best of 20th Century-Technology
Closures
Assertions, unit testing, traces, and tools for finding errors
High level constructs for concurrency
Support for immutable data
Generics (done right)
8
![Page 9: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/9.jpg)
Influences
Static world:
Eiffel, Java, C#, Scala, ...
Dynamic world:
Smalltalk, Python, Scheme/Racket, ...
9
![Page 10: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/10.jpg)
Simplest Programs
Hello, World!
print "Hello, World"
“Top level” code is considered to be inside the “default object”
object { ! print "Hello, World" }
An object with 0 methods and 1 statement
10
Object can contain code that is executed when created
![Page 11: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/11.jpg)
Simple methods
Methods can also be defined and used at the “top level”:
method celsiusToFahrenheit (temp) { ((temp * 9) / 5) + 32}print "20° Celsius is {celsiusToFahrenheit 20}° Fahrenheit"
11
![Page 12: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/12.jpg)
Types are optional
The same code with type annotations:
method celsiusToFahrenheit (temp: Number) -> Number { ((temp * 9) / 5) + 32}print "20° Celsius is {celsiusToFahrenheit 20}° Fahrenheit"
12
‣ Programmer decides whether typing is static, dynamic or …
‣ All options are type-safe
![Page 13: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/13.jpg)
Clean Concepts
numbers
23 2x10111 1.75 1.414214 -1 ! (all exact)
methods on numbers
20 + 43!! 7/4 20.factorial (all exact)
2.sqrt π! ! ! (approximate)
13
![Page 14: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/14.jpg)
Objects
object {! method radius { 5 }! method area { (radius^2)*π }}
14
![Page 15: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/15.jpg)
constant binding
def cost = quantity * unitPrice
def disk = object {! def radius = 5 ! method area { (radius^2)*π }}
15
![Page 16: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/16.jpg)
constants in objects are accessed as methods
disk.radius!! ! ! answers 5disk.area!! ! ! ! answers ~78.53981…
So, it doesn't matter if we define
def disk = object {! def radius = 5 ! method area { (radius^2)*π }}
or
def disk' = object {! method radius { 5 }! method area { (radius^2)*π }}
16
![Page 17: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/17.jpg)
variable binding
var sum := 0
var speed := 2
var invoiceDate := aDate.today
methods and blocks can have temporary variables
objects can have instance variables
17
![Page 18: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/18.jpg)
Instance variables
def adjustableDisk = object {! var radius := 5! method area { (radius^2)*π }}
Instance variables bindings can be changed using methods (unless they are confidential):
adjustableDisk.radius := 1
18
the method is named “radius:=”
![Page 19: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/19.jpg)
object factories:
def aDisk = object {! method ofRadius(r) {! ! object {! ! ! method radius { r }! ! ! method area { (radius^2)*π }! ! ! method > (other) { ! ! ! ! radius > other.radius }! ! }! }}
def myDisk = aDisk.ofRadius(7)
def yourDisk = aDisk.ofRadius(8)
19
![Page 20: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/20.jpg)
Classes codify factories:
class aDisk.ofRadius(r) {! ! ! method radius { r }! ! ! method area { (radius^2)*π }! ! ! method > (other) { ! ! ! ! radius > other.radius }! ! }
def myDisk = aDisk.ofRadius(7)
def yourDisk = aDisk.ofRadius(8)
20
![Page 21: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/21.jpg)
Object composition:
object { ! ! def hole = aDisk.ofRadius (h/2)! ! def outside = aDisk.ofRadius (d/2)! ! method area { outside.area - hole.area }}
class aWasher.holeDiameter (h) outerDiameter (d) {! ! def hole = aDisk.ofRadius (h/2)! ! def outside = aDisk.ofRadius (d/2)! ! method area { outside.area - hole.area }}
21
Grace supports multipart method names (“mixfix”)
![Page 22: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/22.jpg)
Object inheritance:
def cylinder = object { ! ! inherits aDisk.ofRadius (r)! ! def height = h! ! method volume { area * height }}
class aCylinder.baseRadius (r) height (h) {! ! inherits aDisk.ofRadius (r)! ! def height = h! ! method volume { area * height }}
22
![Page 23: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/23.jpg)
Returning multiple results
Grace does not support multiple results. But it’s easy to return an object:
method split (filename) {! ! def dot = filename.indexOf(".")! ! object { ! ! ! ! def base = filename.upto (dot-1)! ! ! ! def extension = filename.from (dot+1) ! ! }}
23
Grace answers an object with 2 methods
![Page 24: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/24.jpg)
Closures
With or without parameters:
{ print "hello" }
{ x,y -> print ("adding " ++ x ++ " to " ++ y ++" gives " ++ (x+y))}
represented by objects with “apply” method
object { method apply(x,y) { print ... }}
Real lexical scope
![Page 25: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/25.jpg)
Building Control Structures
Closures support definition of control constructs in libraries:
class List { method forEach (actionClosure) {...}}
myList.forEach {x -> ...}
![Page 26: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/26.jpg)
Delayed Evaluation Visible
if ( someCond ) then { C } else { D }
while { someCond } do { C }
if ( someCond ) then { C } else { {if ( otherCond ) { D } else { E }}
![Page 27: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/27.jpg)
Other Grace Features
Types (= interfaces) ≠ classes
Visibility: public & confidential
Support for immutable objects
Equals & hashcode built-in (like Eclipse)
Number consists of Rationals & Binary64 floats
![Page 28: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/28.jpg)
Typing DisciplinesExperimentalist (flower child):
Dynamic typing: Do what you want — we’ll make sure it’s safe at run-time ...
TRC regulated:Static typing: We’ll make sure everything is safe before we let you do it.
But semantics of type-safe programs are same either way.
... though some may not be allowed by TRC.
28
![Page 29: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/29.jpg)
All Disciplines InteroperateMixing disciplines helps students/programmers migrate from dynamically to statically typed languages.
What does a type annotation mean in a dynamically typed language?
Represents a claim - generates a dynamic check
like “assert s.nonempty”
What does a type annotation mean in a statically typed language?
Represents provably correct assertion
29
![Page 30: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/30.jpg)
Advanced Features
![Page 31: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/31.jpg)
Pattern Matching
31
method matchTest (x: Number) { match(x) case {1 -> “one”} case {2 -> “two”} case {_ -> “lots”}}
![Page 32: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/32.jpg)
Variant Types
Object types don’t contain null value
Avoid Hoare’s “billion dollar mistake”
Construct as needed from singleton and variant types:
def notThere = object { method asString {...}...}
type Result = String | notThere
![Page 33: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/33.jpg)
Using a variant
33
method doSomething(key: KeyType) { match(table.valueOf(key)) case {v:String -> out.println(... ++ v) lastValue := v case {notThere -> out.println(... ++ " is empty") }}
Provide more powerful pattern matching?
![Page 34: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/34.jpg)
Language Levels
Accomplished via libraries
Libraries package together classes and objects
“use” object or class ⇒ inherit public features
Need to develop useful pedagogical IDEs
34
![Page 35: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/35.jpg)
Why Consider Using Grace?
Clean Syntax
Simple uniform semantic modelno static features, no overloading, no null, etc.
Everything is an object (even lambdas)
Modern featuresGenerics done right, closures, case/pattern matching
Syntax supporting design of control structures
35
![Page 36: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/36.jpg)
Why Consider Using Grace?
Easy transition between dynamic & static type-checking
High level support for parallelism and concurrency (planned)
Likely adopt concurrency constructs similar to those in Habanero Java at Rice:
async{stmts}, finish {stmts}, futures f := async{...}, forall(...) {stmts}, isolated{stmts}
Support for immutable objects
36
![Page 37: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/37.jpg)
Current State of Grace2011: 0.1, 0.2 and 0.3 language releases, prototype implementations ✔
3 implementations in progress, spec at 0.35
2012: 0.8 language spec, mostly complete implementations
2013: 0.9 language spec, reference implementation, experimental classroom use
2014: 1.0 language spec, robust implementations, textbooks, initial adopters for CS1/CS2
2015: ready for general adoption
37
![Page 38: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/38.jpg)
Help!
Supporters
Programmers
Implementers
Library Writers
IDE Developers!!!!
Testers
Teachers
Students
Tech Writers
Textbook Authors
Blog editors
Community Builders
38
![Page 39: And now for something completely differentNow, we are going to tell you about a boring language with no new language features, or uses of language features … And now for something](https://reader035.vdocuments.mx/reader035/viewer/2022070813/5f0cbbdb7e708231d436de0b/html5/thumbnails/39.jpg)
Information, blog, discussion:
http://www.gracelang.org
Try Grace in your browser:
http://homepages.ecs.vuw.ac.nz/~mwh/minigrace/js/
39