Top Banner
When is a langauge not a language? • When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention of undefined execution sequences, ideally before program execution begins.
27

When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Dec 28, 2015

Download

Documents

Morris Gibson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

When is a langauge not a language?

• When it’s well-typed

• Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention of undefined execution sequences, ideally before program execution begins.

Page 2: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Untrapped errors

• When this is not possible, the difference between detected and undetected type errors is still critical.– var x = 3 / 0; // fail – divide by zero– var y = p.name; // fail – no such label– var z = lookup( p, “name” ); // success

• No allowance by programmer

• May lead to wrong answer - undetected

Page 3: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

A database person type

• type person is { name : string, age : int }

function f ( var p : person ){… p.name …… p.address …… p.ape …

}

Page 4: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

A web person

• Can not conform to a rigid type definition– Autonomy

• Independence

• Disagreement

– Evolution– Pre-existing data– (Internationalisation)

• But: probably has a name, maybe age…

Page 5: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

A web person type

• typeof person is { name, age?, other stuff? }typeof name is String | {sname, fname}typeof other stuff is anything

function f ( var p : person ){… p.name …… p.address …… p.ape …

}

Page 6: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

The web-type alchemist’s dream

• A loosely agreed, flexible data model– May change with evolution

– May only be partial wrt actual data

– May be partially inaccurate wrt actual data

• Programs should work correctly– No untrapped error can occur

• Ideally trapped before execution commences

– As the data model changes

– Also world peace would be nice

Page 7: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

The programmer’s task

Data model

Program

Page 8: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Type safety - enforced

Data model

ProgramData

Page 9: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Type safety – by convention

Data model

ProgramData

Page 10: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Safety through convention

• More flexibility– Should work if structural attributes are correct– Should still work if changes occur…

• … which don’t affect the meaning of the code

• Less safety– To achieve this flexibility, something must give

• What, and how much?

Page 11: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

More type safety – by convention

Data model

ProgramData

Validation

Page 12: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Less type safety – by convention

Data model

ProgramData

Validation

Data model’

Page 13: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Less type safety – by convention

Data model

Data

Validation

Data model’

Page 14: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

“Identity” conventions

• URI– UUID

• 094067-0396097546-3002497-34082087

• persons.richard.cis.strath.ac.uk

– URL• http://www.cis.strath.ac.uk/~richard/persons.htm

• xmlns– label to URI binding

• Weak identity – doesn’t capture equality!

Page 15: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Idioms of well-typing

• Interpretation– Program behaves itself, adjusting to context

• Generation– Data and program stubs generated from data

model

• Projection– Data matched against most general program

type

Page 16: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Interpretation

• SAX, DOM, XSLT

• Data is presented to programmer as a tree– Mechanically typed as such

• Type safety requires programming skills– Semantics and context are programmer’s task– Attribute identifiers are treated as strings

• Many errors are not statically detectable

Page 17: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

miniDom interface

• class miniDomTree{   miniDomTree( URL document )   miniDomTree firstChild()   miniDomTree nextSibling()   String incomingEdge() // no direct model   String elementText()}

Page 18: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

miniDOM code

• void printNames( miniDomTree t ){if( t.firstChild != nil )

{ printNames( t.firstChild() ) }if( t.nextSibling != nil)

{ printNames( t.nextSibling() ) }if( t.incomingEdge() == “name” )

{ print( t.elementText() ) }}

Page 19: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

miniSax interface

• interface miniSax{    void openElement( String elementName )    void closeElement( String elementName )    void text( String theText )}

class SaxEngine{   void SaxEngine( URL document )   void runEngine( miniSax whatToDo )}

Page 20: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

miniSAX code• class namePrinter implements miniSax{

private Boolean inName = false

void openElement( String elementName )if( elementName==“name”){ inName = true }

void closeElement( String elementName )if( elementName==“name”){ inName = false }

void text( String theText )      if( inName ){ print( theText ) }

}

Page 21: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

XSLT

• <xsl:template match=“person"><xsl:value-of

select=“name"/></xsl:template>

Page 22: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

All of the above…

• … lead to …

Page 23: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Untrapped type errors!

Page 24: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Generation

Data model

ProgramData

JAXB

XMetal

Validation

xmlns = x

x:URI

xmlns = x

Page 25: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Restrictive: can’t change schema

Page 26: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Leading to…

Page 27: When is a langauge not a language? When it’s well-typed Despite being somewhat unfashionable, type systems keep software partially safe, through the prevention.

Projection

• Ultimate cool!!!