51
Practical Models in Practice www.lukas-renggli.ch

Practical Models in Practice

  • Upload
    choose

  • View
    197

  • Download
    1

Embed Size (px)

DESCRIPTION

presented by Lukas Renggli at the CHOOSE Forum 2012

Citation preview

Page 1: Practical Models in Practice

Practical Modelsin Practicewww.lukas-renggli.ch

Page 2: Practical Models in Practice

Practical Models of Models in Practice

www.lukas-renggli.ch

Page 3: Practical Models in Practice

Practical Meta-Models in Practice

www.lukas-renggli.ch

Page 4: Practical Models in Practice

‣ Software Engineer at GoogleYouTube Video Analytics

‣ SCG AlumniBachelor, Master and PhD

‣ Open-Source CommunitiesSeaside, Magritte and PierHelvetia, PetitParser

Lukas Renggli

Page 5: Practical Models in Practice

Roadmap1. Protocol Buffers

Meta-data model for serialization2. Magritte

Meta-model for generic services3. Google Web Toolkit

Model-driven web architecture4. Helvetia

Meta-model for programming languages

Page 6: Practical Models in Practice

1Protocol BuffersMeta-data model for serialization

Page 7: Practical Models in Practice

Protocol Buffers

‣ Encode structured data‣ Language-neutral‣ Platform-neutral‣ Extensible‣ Efficient

Page 8: Practical Models in Practice

Protocol Buffer IDL

message Person {  required int32 id = 1;  required string name = 2;  optional string email = 3;}

Page 9: Practical Models in Practice

message Person {  required int32 id = 1;  required string name = 2;  optional string email = 3;}

C++

protoc

Page 10: Practical Models in Practice

Serialize in C++

Person person;person.set_name("John Doe");person.set_id(1234);person.set_email("[email protected]");

fstream output("myfile", ios::out | ios::binary);person.SerializeToOstream(&output);

Page 11: Practical Models in Practice

Deserialize in Python

file = open("myfile", "rb")person = Person()person.ParseFromString(file.read())file.close

print "Name: ", person.nameprint "E-mail: ", person.email

Page 12: Practical Models in Practice

Demo

Page 13: Practical Models in Practice

Why not XML/JSON?

‣ Protocol Buffers are– 3—10 times smaller– 20—100 times faster– consistent code generators– less ambiguous– evolvable

Page 14: Practical Models in Practice

message Person {  required int32 id = 1;  required string name = 2;  optional string email = 3;}

message Person {  required int32 id = 1;  required string name = 2;  repeated string email = 3; repeated Phone phone = 4;}

:Person:Person

:Person

Page 15: Practical Models in Practice

‣ Describe your data once, and use it across platforms and languages‣ Evolution supported by design‣ Used at Google for almost all

– data storage (file formats, database)– remote procedure protocols (RPC)

Page 16: Practical Models in Practice

2MagritteMeta-model for generic services

Page 17: Practical Models in Practice

Address Object

street = 'Schützenmattstrasse'plz = 3012place = 'Bern'canton = 'Bern'

:Address

Page 18: Practical Models in Practice

Address Class

street = 'Schützenmattstrasse'plz = 3012place = 'Bern'canton = 'Bern'

:Address

street: Stringplz: Integerplace: Stringcanton: String

Address

class

Page 19: Practical Models in Practice

Address Description

street = 'Schützenmattstrasse'plz = 3012place = 'Bern'canton = 'Bern'

:Address

label = 'Street'

:StringDescription

label = 'PLZ'required = truerange = 1000..9999

:NumberDescription

label = 'Place'required = true

:StringDescription

label = 'Canton'required = truesorted = trueoptions = #( 'Bern' 'Zurich' ... )

:SingleOptionDescription

label = 'Address'

:Containerdescription

Magritte

Page 20: Practical Models in Practice

result := anAddress asMorph addButtons; addWindow; callInWorld

User Interfaces

Page 21: Practical Models in Practice

result := self call: (anAddress asComponent addValidatedForm; yourself)

Web Interfaces

*

*

*

Page 22: Practical Models in Practice

Other ServicesViewers

EditorsReports

ValidationFiltering

Serialization

Copying

IndexingInitialization

Initialization

ExtensionAdaptation

Customization

Page 23: Practical Models in Practice

Domain Model

Metamodel

Meta-

Metamodel

<described-by>

<described-by>

Developer

End User

Page 24: Practical Models in Practice

Domain Model

Metamodel

Meta-

Metamodel

Magritte

Developer

<described-by>

<described-by>

Magritte

End User

Page 25: Practical Models in Practice

Adaptive Object Model

Run-time

Page 26: Practical Models in Practice

End userscustomizability

Page 27: Practical Models in Practice

Demo

Page 28: Practical Models in Practice

‣ Very powerful and flexible‣ Runtime adaptive code‣ End-user programmable code‣ Can cause meta meta-confusion‣ Can be slower than hardcoding

Magritte

Page 29: Practical Models in Practice

3Google Web ToolkitModel-driven web architecture

Page 30: Practical Models in Practice

public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}

Is this really a model?

Page 31: Practical Models in Practice

public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}

Is this really a model?

High-levelWidgets

Page 32: Practical Models in Practice

public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}

Is this really a model?

High-levelWidgets

DescriptionLanguage

Page 33: Practical Models in Practice

platformindependentmodel

modeltransformation

public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}

Page 34: Practical Models in Practice

Transformation

Mozilla Chrome Safari IE ...

English

French

German

...

Page 35: Practical Models in Practice

‣ Write JavaScript using a high-level widget library in a well defined (statically typed) language‣ Translate and optimize code towards

specific browsers‣ Debugging actually works nowadays

GWT

Page 36: Practical Models in Practice

4HelvetiaMeta-model for programming languages

He vetia

Page 37: Practical Models in Practice
Page 38: Practical Models in Practice
Page 39: Practical Models in Practice
Page 40: Practical Models in Practice

ProgrammingLanguage

Model

Page 41: Practical Models in Practice

a..z a..z

0..9

ID  ::=  letter  {  letter  |  digit  }  ;

Page 42: Practical Models in Practice

scanIdentifier self step. ((currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ]) ifTrue: [ [ self recordMatch: #IDENTIFIER. self step. (currentCharacter between: $0 and: $9)or: [ (currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ] ] ] whileTrue. ^ self reportLastMatch ]

Page 43: Practical Models in Practice

#(#[1 0 9 0 25 0 13 0 34 0 17 0 40 0 21 0 41] #[1 0 9 0 25 0 13 0 34 0 93 0 76 0 157 0 112] #[1 2 38 0 21 2 38 0 25 2 38 0 26 0 13 0 34] #[0 1 154 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[0 1 210 0 76 0 81] #[0 1 214 0 76 0 81] #[1 0 173 0 76 0 177 0 81] #[0 1 134 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[1 1 46 0 21 1 46 0 25 1 46 0 26 1 69] #[1 1 54 0 21 1 54 0 25 1 54 0 26 1 54 0 34] #[0 2 102 0 21 0 25 0 26 0 34 0 40 0 41 0 76]

#[0 2 50 0 21 0 25 0 26 0 76 0 79] #[1 1 13 0 76 2 85 0 124 1 21 0 125] #[1 2 89 0 17 2 30 0 21 2 30 0 82] #[1 2 93 0 21 2 97 0 82] )

Page 44: Practical Models in Practice

a..z a..z

0..9

ID  ::=  letter  {  letter  |  digit  }  ;

44

Page 45: Practical Models in Practice

letter

letter digit

sequence

choice

many

ID  ::=  letter  {  letter  |  digit  }  ;

45

Page 46: Practical Models in Practice

letter

letter digit

sequence

choice

many

46

Transformable

Composable

Extensible

Customizable

Page 47: Practical Models in Practice

letter

letter digit

sequence

choice

many

47

He vetiaContextual

Menus

NavigationSearch

CodeExpansion

ErrorCorrection

CustomInspector

Refactorings

CodeFolding

CodeHighlighting

Debuggers

Editors

Page 48: Practical Models in Practice

Demo

Page 49: Practical Models in Practice

‣ Grammar is the meta-model‣ Composable programming languages‣ Extensible programming languages‣ Tooling is built around the grammar

He vetia

Page 50: Practical Models in Practice

StructuralModel

BehavioralModel

Run-

time

Stat

icRu

n-tim

eAd

aptiv

e

He vetia

Page 51: Practical Models in Practice

“Meta-models are the enablers ofpractical software development.”

www.lukas-renggli.ch

He vetia