mobl - model-driven engineering lecture

171
Zef Hemel http://www.mobl-lang.org

Upload: zefhemel

Post on 15-May-2015

2.383 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: mobl - model-driven engineering lecture

Zef Hemel

http://www.mobl-lang.org

Page 2: mobl - model-driven engineering lecture
Page 3: mobl - model-driven engineering lecture

230,000 300,000

Page 4: mobl - model-driven engineering lecture
Page 5: mobl - model-driven engineering lecture

Objective-C Java J2ME/C++

HTML/Javascript Java .NET

Page 6: mobl - model-driven engineering lecture

portability

Page 7: mobl - model-driven engineering lecture

Objective-C Java J2ME/C++

HTML/Javascript Java .NET

Page 8: mobl - model-driven engineering lecture

Webkit browser Webkit browser J2ME/C++

Webkit browser Webkit browser .NET

Page 9: mobl - model-driven engineering lecture
Page 10: mobl - model-driven engineering lecture

WebDatabases

Page 11: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Page 12: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Canvas

Page 13: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Canvas

Multi-touch

Page 14: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Canvas

Multi-touch

Offline support

Page 15: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Canvas

Multi-touch

Offline support

Full-screen support

Page 16: mobl - model-driven engineering lecture

WebDatabases

Location information (GPS)

Canvas

Multi-touch

Offline support

Full-screen support

Accelerator support

Page 17: mobl - model-driven engineering lecture
Page 18: mobl - model-driven engineering lecture

Address book

Page 19: mobl - model-driven engineering lecture

Address book

Camera

Page 20: mobl - model-driven engineering lecture

Address book

Camera

Compass

Page 21: mobl - model-driven engineering lecture

Address book

Camera

Compass

File IO

Page 22: mobl - model-driven engineering lecture

Address book

Camera

Compass

File IO

Audio

Page 23: mobl - model-driven engineering lecture

Address book

Camera

Compass

File IO

Audio

Notifications

Page 24: mobl - model-driven engineering lecture
Page 25: mobl - model-driven engineering lecture
Page 26: mobl - model-driven engineering lecture
Page 27: mobl - model-driven engineering lecture
Page 28: mobl - model-driven engineering lecture
Page 29: mobl - model-driven engineering lecture

mobl program

Page 30: mobl - model-driven engineering lecture

1. language

2. behind the scenes

today

Page 31: mobl - model-driven engineering lecture

language

Page 32: mobl - model-driven engineering lecture

user interface

styling

data modeling

scripting

web services

Page 33: mobl - model-driven engineering lecture

user interface

Page 34: mobl - model-driven engineering lecture

demo

Page 35: mobl - model-driven engineering lecture

screen name(farg*) : ReturnType? { screenelem*}

control name(farg*) { screenelem*}

ui syntax

Page 36: mobl - model-driven engineering lecture

screen root() { ...}

Page 37: mobl - model-driven engineering lecture

screen root() { ...}

screen promptString(q : String) : String { ...}

Page 38: mobl - model-driven engineering lecture

screen root() { ...}

screen promptString(q : String) : String { ...}

control button(s : String, onclick : Callback = {}) { ...}

Page 39: mobl - model-driven engineering lecture

control calls

variable declarations

inline HTML

script blocks

control structures

Page 40: mobl - model-driven engineering lecture

button("Click me")

control calls

Page 41: mobl - model-driven engineering lecture

button("Click me")

button("Click me", { alert("Click!");})

control calls

Page 42: mobl - model-driven engineering lecture

button("Click me")

button("Click me", { alert("Click!");})

button("Click me", onclick={ alert("Click!");})

control calls

Page 43: mobl - model-driven engineering lecture

group() { item() { "Item 1" } item() { "Item 2" }}

control calls with body

Page 44: mobl - model-driven engineering lecture

group { item { "Item 1" } item { "Item 2" }}

control calls with body

Page 45: mobl - model-driven engineering lecture

variable declarations

var b = true

Page 46: mobl - model-driven engineering lecture

variable declarations

var b = truevar b : Bool = true

Page 47: mobl - model-driven engineering lecture

variable declarations

var b = true

var newTask = Task()

var b : Bool = true

Page 48: mobl - model-driven engineering lecture

variable declarations

var b = true

var newTask = Task()

var b : Bool = true

var newTask : Task = Task()

Page 49: mobl - model-driven engineering lecture

when

var b = true

checkBox(b)

when(b) { label("Yep")} else { label("Nope")}

Page 50: mobl - model-driven engineering lecture

list

var nums = [1, 2, 3]

group { list(n in nums) { item { label(n) } }}

Page 51: mobl - model-driven engineering lecture

inline HTML

<img src="img/icon.png"/>

Page 52: mobl - model-driven engineering lecture

inline HTML

<img src="img/icon.png"/>

<div class=selected ? selectedStyle : notSelectedStyle> ...</div>

Page 53: mobl - model-driven engineering lecture

script blocks

var n = -1script { n = Math.sqrt(9);}

avoid if possible

Page 54: mobl - model-driven engineering lecture

higher-order controls

Page 55: mobl - model-driven engineering lecture

demo

Page 56: mobl - model-driven engineering lecture

styling

Page 57: mobl - model-driven engineering lecture

style bigAndBlue { color: blue; font-size: 40px;}

Page 58: mobl - model-driven engineering lecture

style bigAndBlue { color: blue; font-size: 40px;}

Style

Page 59: mobl - model-driven engineering lecture

control block(style : Style) { ...}

block(bigAndBlueStyle) { label("I am big and blue!");}

Page 60: mobl - model-driven engineering lecture

style $baseColor = rgb(100, 100, 100)

style myStyle { color: rgb($baseColor.r+10, $baseColor.g+50, $baseColor.b-20); font-size: 20px;}

Page 61: mobl - model-driven engineering lecture

style mixin borderRadiusMixin($radius) { -moz-border-radius: $radius; -webkit-border-radius: $radius; border-radius: $radius;}

Page 62: mobl - model-driven engineering lecture

style mixin borderRadiusMixin($radius) { -moz-border-radius: $radius; -webkit-border-radius: $radius; border-radius: $radius;}

style myStyle { color: $baseColor; borderRadiusMixin(10px);}

Page 63: mobl - model-driven engineering lecture

demo

Page 64: mobl - model-driven engineering lecture

data modeling& query

Page 65: mobl - model-driven engineering lecture

entity Task { name : String (searchable) done : Bool tags : Collection<Tag> (inverse: tasks)}

entity Tag { name : String (searchable) tasks : Collection<Task> (inverse: tags)}

Page 66: mobl - model-driven engineering lecture

var newTask = Task(name="New task");newTask.done = false;add(newTask);

Page 67: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Page 68: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Collection<Task>

Page 69: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Collection<Task>

.filter("done", "=", true)

.order("date", false)

.limit(10);

Page 70: mobl - model-driven engineering lecture

var tagDoneTasks = tag.tasks .filter("done", "=", true) .order("date", false) .limit(10);

Collection<Task>

Page 71: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Collection<Task>

Page 72: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Collection<Task>

where done == trueorder by date desclimit 10;

Page 73: mobl - model-driven engineering lecture

var tagDoneTasks = tag.tasks where done == true order by date desc limit 10;

Collection<Task>

Page 74: mobl - model-driven engineering lecture

var searchTasks = Task.search("task") where done == true limit 10;

Collection<Task>

Page 75: mobl - model-driven engineering lecture

screen root() { header("Tasks") group { list(t in Task.all() order by date desc) { item { label(t.name) } } }}

Page 76: mobl - model-driven engineering lecture

scripting

Page 77: mobl - model-driven engineering lecture

label("Total tasks: " + Task.all().count())

script in ui

Page 78: mobl - model-driven engineering lecture

button("Click me", onclick={ alert("You clicked me!");})

label("Total tasks: " + Task.all().count())

script in ui

Page 79: mobl - model-driven engineering lecture

var n = 7;var n2 = Math.round(n/2);

if(n2 > 3) { alert("More than three!");} else { alert("Less than three!");}

Page 80: mobl - model-driven engineering lecture

var n = 7;var n2 = Math.round(n/2);

if(n2 > 3) { alert("More than three!");} else { alert("Less than three!");}

type inference

Page 81: mobl - model-driven engineering lecture

var done = 0;foreach(t in Task.all()) { if(t.done) { done = done + 1; }}

Page 82: mobl - model-driven engineering lecture

var done = 0;foreach(t in Task.all()) { if(t.done) { done = done + 1; }}

var done = (Task.all() where done == true) .count();

Page 83: mobl - model-driven engineering lecture

function sqr(n : Num) : Num { return n * n;}

Page 84: mobl - model-driven engineering lecture

demo: todo list

Page 85: mobl - model-driven engineering lecture

web serviceaccess

Page 86: mobl - model-driven engineering lecture

service SomeService { resource tasks() : JSON { uri = "/tasks" }

resource search(query : String) : JSON { uri = "/search?q=" + escape(query) }}

Page 87: mobl - model-driven engineering lecture

service Twitter { resource trends() : JSON { uri = "/_proxy/api.twitter.com/1/trends.json" }

resource search(query : String) : JSON { uri = "/_proxy/search.twitter.com/search.json?q=" + escape(query) }}

ajax same-source restriction

Page 88: mobl - model-driven engineering lecture

{"trends": [{"url":"http:\/\/search.twitter.com\/search?q=...", "name":"#ihaveadream"}, {"url":"http:\/\/search.twitter.com\/search?q=...", "name":"#mlkday"} ... ]}

http://api.twitter.com/1/trends.json

Page 89: mobl - model-driven engineering lecture

type Trend { name : String url : String}

function trendsMapper(json : JSON) : [Trend] { return json.trends;}

Page 90: mobl - model-driven engineering lecture

resource trends() : JSON { uri = "/_proxy/api.twitter.com/1/trends.json" mapper = trendsMapper}

Page 91: mobl - model-driven engineering lecture

screen root() { var trends = Twitter.trends()

header("Twitter trends") group { list(topic in trends) { item { label(topic.name) } } }}

Page 92: mobl - model-driven engineering lecture

user interface

styling

data modeling

scripting

web services

Page 93: mobl - model-driven engineering lecture

slower than native

no native UI

not great for games

limitations

Page 94: mobl - model-driven engineering lecture

behind the scenes

Page 95: mobl - model-driven engineering lecture

goals

coverage

portability

completeness

Page 96: mobl - model-driven engineering lecture

goals

coverage

portability

completeness

web

Page 97: mobl - model-driven engineering lecture

goals

coverage

portability

completeness 100% code gen

web

Page 98: mobl - model-driven engineering lecture

design bottom-up

Page 99: mobl - model-driven engineering lecture

1. design core abstractions + native interface

roadmap

Page 100: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

roadmap

Page 101: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

roadmap

Page 102: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

roadmap

Page 103: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

roadmap

Page 104: mobl - model-driven engineering lecture

synchronous programming

core abstraction:

no more asynchronous spaghetti code

Page 105: mobl - model-driven engineering lecture

var results = Task.all().list();for(var i = 0; i < results.length; i++) { alert(results[i].name);}

synchronous programming

Page 106: mobl - model-driven engineering lecture

render page

query database and process

results

...

time

Page 107: mobl - model-driven engineering lecture

render page

query database and process

results

...

timebrowser freeze

Page 108: mobl - model-driven engineering lecture

render page

send query

...

process query result

...

time

Page 109: mobl - model-driven engineering lecture

Task.all.list(function(results) { for(var i = 0; i < results.length; i++) { alert(results[i].name); } });...

asynchronous programming

Page 110: mobl - model-driven engineering lecture

Task.all().list(function(results) { alert("Hello, "); });alert("world!");

Page 111: mobl - model-driven engineering lecture

Task.all().list(function(results) { alert("Hello, "); });alert("world!");

breaks sequential execution assumption

Page 112: mobl - model-driven engineering lecture

Task.all().list(function(results) { // make changes ... persistence.flush(function() { alert("Changes saved!"); });});

Page 113: mobl - model-driven engineering lecture

continuation-passing styletransformation

Page 114: mobl - model-driven engineering lecture

function displayLocationAndReturn() : Coordinates { var position = mobl::location::getPosition(); log("Lat: " + position.latitude); log("Long: " + position.longitude); return position;}

Page 115: mobl - model-driven engineering lecture

function displayLocationAndReturn() : Coordinates { var position = mobl::location::getPosition(); log("Lat: " + position.latitude); log("Long: " + position.longitude); return position;}

function displayLocationAndReturn(callback) { mobl.location.getPosition(function(position) { console.log("Lat: " + position.latitude); console.log("Long: " + position.longitude); callback(position); });};

Page 116: mobl - model-driven engineering lecture

function displayLocationAndReturn() : Coordinates { var position = mobl::location::getPosition(); log("Lat: " + position.latitude); log("Long: " + position.longitude); return position;}

function displayLocationAndReturn(callback) { mobl.location.getPosition(function(position) { console.log("Lat: " + position.latitude); console.log("Long: " + position.longitude); callback(position); });};

Page 117: mobl - model-driven engineering lecture

function displayLocationAndReturn() : Coordinates { var position = mobl::location::getPosition(); log("Lat: " + position.latitude); log("Long: " + position.longitude); return position;}

function displayLocationAndReturn(callback) { mobl.location.getPosition(function(position) { console.log("Lat: " + position.latitude); console.log("Long: " + position.longitude); callback(position); });};

Page 118: mobl - model-driven engineering lecture

data bindingcore abstraction:

no more copying data from and to UI

Page 119: mobl - model-driven engineering lecture

screen root() { var n = 8 label(n * n) button("Inc", onclick={ n = n + 1; })}

Page 120: mobl - model-driven engineering lecture

var n = 8

var n = ref(8);

Page 121: mobl - model-driven engineering lecture

var n = 8

var n = ref(8);

Observable- set(value)- get()- addEventListener(eventType, callback)

Page 122: mobl - model-driven engineering lecture

label(n * n)

var node = $("<span>");node.text(n.get() * n.get());n.addEventListener("change", function() { node.text(n.get() * n.get());});root.append(node);

Page 123: mobl - model-driven engineering lecture

label(n * n)

var node = $("<span>");node.text(n.get() * n.get());n.addEventListener("change", function() { node.text(n.get() * n.get());});root.append(node);

Page 124: mobl - model-driven engineering lecture

label(n * n)

var node = $("<span>");node.text(n.get() * n.get());n.addEventListener("change", function() { node.text(n.get() * n.get());});root.append(node);

Page 125: mobl - model-driven engineering lecture

button("Inc", onclick={ n = n + 1;})

var node = $("<button ...>");node.text("Inc");node.click(function() { n.set(n.get() + 1);});root.append(node);

Page 126: mobl - model-driven engineering lecture

button("Inc", onclick={ n = n + 1;})

var node = $("<button ...>");node.text("Inc");node.click(function() { n.set(n.get() + 1);});root.append(node);

Page 127: mobl - model-driven engineering lecture

screen root() { var n = 8 label(n * n) button("Inc", onclick={ n = n + 1; })}

Page 128: mobl - model-driven engineering lecture

screen root() { var n = 8 label(n * n) button("Inc", onclick={ n = n + 1; })}

Page 129: mobl - model-driven engineering lecture

screen root() { var n = 8 label(n * n) button("Inc", onclick={ n = n + 1; })}

Page 130: mobl - model-driven engineering lecture

data modeling & query

core abstraction:

no more SQL

Page 131: mobl - model-driven engineering lecture

uses persistence.jshttp://persistencejs.org

Page 132: mobl - model-driven engineering lecture

entity Task { name : String (searchable) description : String (searchable) done : Bool date : DateTime}

var Task = persistence.define('Task', { name: 'VARCHAR(255)', description: 'VARCHAR(255)', done: 'BOOL', date: 'DATE'});

Task.textIndex('description');Task.textIndex('name');

Page 133: mobl - model-driven engineering lecture

foreach(t in Task.all()) { alert(t.name);}

Task.all().forEach(function(t) { alert(t.name);});

Page 134: mobl - model-driven engineering lecture

foreach(t in Task.all() where done == true) { alert(t.name);}

Task.all().filter("done", "=", true).forEach(function(t) { alert(t.name);});

Page 135: mobl - model-driven engineering lecture

native interface

Page 136: mobl - model-driven engineering lecture

external entity MyEntity

external control contextMenu()

external screen specialScreen()

external sync function add(o : Object) : void

external style myStyle

external type MyType

Page 137: mobl - model-driven engineering lecture

external sync function add(o : Object) : void

<javascript>__ns.add = function(o) { persistence.add(o);};</javascript>

Page 138: mobl - model-driven engineering lecture

load styles/default.cssload js/persistence.js

Page 139: mobl - model-driven engineering lecture

where do abstractions come from?

Page 140: mobl - model-driven engineering lecture

where do abstractions come from?

domain

Page 141: mobl - model-driven engineering lecture

where do abstractions come from?

domain

experience

Page 142: mobl - model-driven engineering lecture

domain

Page 143: mobl - model-driven engineering lecture

domain

screen

Page 144: mobl - model-driven engineering lecture

domain

screen

control

Page 145: mobl - model-driven engineering lecture

domain

screen

control

entity

Page 146: mobl - model-driven engineering lecture

domain

screen

control

entity

event

Page 147: mobl - model-driven engineering lecture

domain

screen

control

entity

event web service

Page 148: mobl - model-driven engineering lecture

experience

Page 149: mobl - model-driven engineering lecture

experience

other DSLs

Page 150: mobl - model-driven engineering lecture

experience

programming paradigms

other DSLs

Page 151: mobl - model-driven engineering lecture

experience

programming paradigms

annoyancesother DSLs

Page 152: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

roadmap

Page 153: mobl - model-driven engineering lecture

goal

compiler small

library large (and extensible)

Page 154: mobl - model-driven engineering lecture

how?

- built-in types- built-in controls

+ native interface+ sufficiently low-level primitives+ abstraction mechanisms (screens, controls, functions, types)

Page 155: mobl - model-driven engineering lecture

native interfaceexternal type Object { sync function toString() : String}

external type String : Object { length : Num sync function charAt(index : Num) : String sync function charCodeAt(index : Num) : Num ...}

external type Num : Object { }external type Bool : Object { }external type Dynamic : Object { }external type Style : String { }

external type Array<T> { length : Num

sync function get(n : Num) : T sync function push(item : T) : void sync function join(sep : String) : String ...}

Page 156: mobl - model-driven engineering lecture

control image(url : String, onclick : Callback = null) { <img src=url onclick=onclick/>}

low-level primitives

Page 157: mobl - model-driven engineering lecture

control slideupBlock() { div@<div onclick={ div.slideUp(); }> elements() </div>}

...

slideupBlock { label("Click me to slide up")}

low-level primitives

Page 158: mobl - model-driven engineering lecture

control slideupBlock() { div@<div onclick={ div.slideUp(); }> elements() </div>}

...

slideupBlock { label("Click me to slide up")}

low-level primitives

JQuery

Page 159: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

roadmap

Page 160: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Page 161: mobl - model-driven engineering lecture

var doneTasks = Task.all().filter("done", "=", true).order("date", false).limit(10);

Page 162: mobl - model-driven engineering lecture

var doneTasks = Task.all()

Page 163: mobl - model-driven engineering lecture

var doneTasks = Task.all()where done == trueorder by date desclimit 10;

Page 164: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

roadmap

Page 165: mobl - model-driven engineering lecture

load styles/default.css

Page 166: mobl - model-driven engineering lecture

div.header { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(72, 100, 180)), to(rgb(32, 60, 140))); background: -moz-linear-gradient(top, rgb(72, 100, 180), rgb(32, 60, 140)); padding: 0; height: 2.3em; font-size: 1.3em; line-height: 2.3em; font-weight: bold; text-align: center; text-shadow: #477 0px 1px 1px; color: white; font-weight: bold; margin: 0; z-index: 2;}

Page 167: mobl - model-driven engineering lecture

issue

out of sight,out of mind no checking

<div class="headerr"></div>

Page 168: mobl - model-driven engineering lecture

little abstraction

div.header { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(72, 100, 180)), to(rgb(32, 60, 140))); background: -moz-linear-gradient(top, rgb(72, 100, 180), rgb(32, 60, 140)); padding: 0; height: 2.3em; font-size: 1.3em; line-height: 2.3em; font-weight: bold; text-align: center; text-shadow: #477 0px 1px 1px; color: white; font-weight: bold; margin: 0; z-index: 2;}

Page 169: mobl - model-driven engineering lecture

little abstraction

div.header { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(72, 100, 180)), to(rgb(32, 60, 140))); background: -moz-linear-gradient(top, rgb(72, 100, 180), rgb(32, 60, 140)); padding: 0; height: 2.3em; font-size: 1.3em; line-height: 2.3em; font-weight: bold; text-align: center; text-shadow: #477 0px 1px 1px; color: white; font-weight: bold; margin: 0; z-index: 2;}

mixins

Page 170: mobl - model-driven engineering lecture

1. design core abstractions + native interface

2. enable user land abstractions

3a. support successful ULAs with syntax

3b. support common native interface cases with core abstractions

Page 171: mobl - model-driven engineering lecture

http://www.mobl-lang.org