Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Grace : the Absence of (Inessential) Difficulty

Kim Bruce
October 23, 2012

Grace : the Absence of (Inessential) Difficulty

Presentation on Grace by Andrew Black and Kim Bruce at Onward! 2012

Kim Bruce

October 23, 2012
Tweet

Other Decks in Education

Transcript

  1. Grace : the Absence of (Inessential) Difficulty Andrew P. Black,

    Kim. B. Bruce, James Noble and Michael Homer
  2. Onward! 2012 Why Grace ? • Claim: no existing language

    is a good choice for a teaching object-oriented programming ° Every one requires that students spend more time mastering the language than learning the fundamentals of object-orientation. • For novices, the “inessential” or “accidental” difficulty of the language often dominates the “essential” difficulty of programming 2
  3. Grace : the Absence of (Inessential) Difficulty Andrew P. Black,

    Kim. B. Bruce, James Noble and Michael Homer The complexity of software is an essential property, not an accidental one Fred Brooks, 1986 Grace is the absence of everything that indicates pain or difficulty, hesitation or incongruity. Wi!iam Hazlitt, 1817
  4. Onward! 2012 Goals Integrate proven newer ideas in programming languages

    into a simple, general-purpose teaching language whose features represent the key concepts of object oriented-programming directly, simply and gracefu!y 4
  5. Onward! 2012 Goals • “Simple” ° ~ 50 page spec

    ° small number of concepts to learn ° each concept has power to “explain” a lot about the language • But not a toy ° Extensible through libraries • Looking towards distributed and parallel implementation ° Support immutable objects 5
  6. Onward! 2012 Grace in one slide method average -> Number

    // reads numbers from this stream and averages { var total := 0 var count := 0 until {atEnd} do { count := count + 1 total := total + readNumber } if (count = 0) then {return 0} total / count } 6 Might appear in a stream object implicit self. implicit self. until()do() is a method Е- Е- nested scope
  7. Backward! 2012 What’s new? Not much! • This is by

    design! ° accessible to instructors, most of whom are not programming language buffs • The Onward! paper focusses on 1. Constructing objects 2. Types 3. “Language Levels” 4. Implementation 7
  8. Onward! 2012 Constructing Objects 9 Object Construction Instantiate Class Clone

    Prototype Class is not an Object Class is an Object
  9. Onward! 2012 10 Instantiate Class Class is not an Object

    Class is an Object meta-level construct instance initialization is messy small number of concepts mind-boggling consequences many extra concepts
  10. Onward! 2012 11 Clone Prototype Where do the Prototypes come

    from? • Prototypes of basic objects are present ab initio • What about user defined objects? ° start with a basic object and mutate it by adding fields and methods 㱺 all objects are mutable not “mainstream”
  11. Onward! 2012 Constructing Objects 12 Object Construction Instantiate Class Clone

    Prototype Class is not an Object Class is an Object
  12. Onward! 2012 A Third Way 13 Object Construction Instantiate Class

    Clone Prototype Class is not an Object Class is an Object Execute object constructor
  13. Onward! 2012 Constructing Grace Objects object { ! def name

    is readable, public = "Wackiki Wabbit" ! def address is readable, public = ! ! ! ! ! ! ! ! ! ! ! "[email protected]" ! method email is public { ! ! EmailApp.openComposerWindowTo(name) ! } } 14 New language feature: the object constructor Defines fields Defines fields Defines methods protocol is name, address, email
  14. Onward! 2012 Constructing many Objects • Repeatedly execute an object

    constructor: set.map { each -> ! object { ! ! def name is readable, public = each.first ! ! def address is readable, public = each.second ! ! method email is public { ! ! ! EmailApp.openComposerWindowTo(name) ! ! } ! } } 15 internal iterator method λ-expression name initialized using each, from surrounding lexical scope each is parameter
  15. Onward! 2012 • an object containing a method that constructs

    an object: def anAddressCard = object { ! method for (aName) at (anAddress) { ! ! object { ! ! ! def name is readable, public = aName ! ! ! def address is readable, public = anAddress ! ! ! method email is public { ! ! ! ! EmailApp.openComposerWindowTo(name) ! ! ! } ! ! } ! } } 16 Factory Object name is initialized to parameter of factory method factory method is called for()at() factory object, has a single method
  16. Onward! 2012 • Class syntax: ° defines a class object,

    its factory method, and the fields and methods of the objects that it creates class anAddressCard.for (aName) at (anAddress) { !! ! ! def name is readable, public = aName ! ! def address is readable, public = anAddress ! ! method email is public { ! ! ! EmailApp.openComposerWindowTo(name) ! ! } } 17 Factory Object = Class
  17. Onward! 2012 Inheritance • Any object can inherit from a

    superobject ° given in the object constructor ° must be newly-created, and manifest ° fields and methods of the superobject are inherited by its heir • Note that the fields of the superobject are already initialized 18
  18. Onward! 2012 Example: PhoneCard def wwPhoneCard = ! object {

    ! ! inherits anAddressCard.for "Wackiki Wabbit" ! ! ! address "[email protected]" ! ! def phoneNumber is readable, public = ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "866-373-4389" ! ! method call { ! ! ! PhoneDialer.dial(phoneNumber) ! ! } ! } • wwPhoneCard inherits the three methods of its superobject as well as the two new methods 19