practical models in practice
DESCRIPTION
presented by Lukas Renggli at the CHOOSE Forum 2012TRANSCRIPT
Practical Modelsin Practicewww.lukas-renggli.ch
Practical Models of Models in Practice
www.lukas-renggli.ch
Practical Meta-Models in Practice
www.lukas-renggli.ch
‣ Software Engineer at GoogleYouTube Video Analytics
‣ SCG AlumniBachelor, Master and PhD
‣ Open-Source CommunitiesSeaside, Magritte and PierHelvetia, PetitParser
Lukas Renggli
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
1Protocol BuffersMeta-data model for serialization
Protocol Buffers
‣ Encode structured data‣ Language-neutral‣ Platform-neutral‣ Extensible‣ Efficient
Protocol Buffer IDL
message Person { required int32 id = 1; required string name = 2; optional string email = 3;}
message Person { required int32 id = 1; required string name = 2; optional string email = 3;}
C++
protoc
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);
Deserialize in Python
file = open("myfile", "rb")person = Person()person.ParseFromString(file.read())file.close
print "Name: ", person.nameprint "E-mail: ", person.email
Demo
Why not XML/JSON?
‣ Protocol Buffers are– 3—10 times smaller– 20—100 times faster– consistent code generators– less ambiguous– evolvable
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
‣ 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)
2MagritteMeta-model for generic services
Address Object
street = 'Schützenmattstrasse'plz = 3012place = 'Bern'canton = 'Bern'
:Address
Address Class
street = 'Schützenmattstrasse'plz = 3012place = 'Bern'canton = 'Bern'
:Address
street: Stringplz: Integerplace: Stringcanton: String
Address
class
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
result := anAddress asMorph addButtons; addWindow; callInWorld
User Interfaces
result := self call: (anAddress asComponent addValidatedForm; yourself)
Web Interfaces
*
*
*
Other ServicesViewers
EditorsReports
ValidationFiltering
Serialization
Copying
IndexingInitialization
Initialization
ExtensionAdaptation
Customization
Domain Model
Metamodel
Meta-
Metamodel
<described-by>
<described-by>
Developer
End User
Domain Model
Metamodel
Meta-
Metamodel
Magritte
Developer
<described-by>
<described-by>
Magritte
End User
Adaptive Object Model
Run-time
End userscustomizability
Demo
‣ Very powerful and flexible‣ Runtime adaptive code‣ End-user programmable code‣ Can cause meta meta-confusion‣ Can be slower than hardcoding
Magritte
3Google Web ToolkitModel-driven web architecture
public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}
Is this really a model?
public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}
Is this really a model?
High-levelWidgets
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
platformindependentmodel
modeltransformation
public class Main implements EntryPoint { public void onModuleLoad() { Label label = new Label(“Hello World”); RootPanel.add(label); }}
Transformation
Mozilla Chrome Safari IE ...
English
French
German
...
‣ 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
4HelvetiaMeta-model for programming languages
He vetia
ProgrammingLanguage
Model
a..z a..z
0..9
ID ::= letter { letter | digit } ;
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 ]
#(#[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] )
a..z a..z
0..9
ID ::= letter { letter | digit } ;
44
letter
letter digit
sequence
choice
many
ID ::= letter { letter | digit } ;
45
letter
letter digit
sequence
choice
many
46
Transformable
Composable
Extensible
Customizable
letter
letter digit
sequence
choice
many
47
He vetiaContextual
Menus
NavigationSearch
CodeExpansion
ErrorCorrection
CustomInspector
Refactorings
CodeFolding
CodeHighlighting
Debuggers
Editors
Demo
‣ Grammar is the meta-model‣ Composable programming languages‣ Extensible programming languages‣ Tooling is built around the grammar
He vetia
StructuralModel
BehavioralModel
Run-
time
Stat
icRu
n-tim
eAd
aptiv
e
He vetia
“Meta-models are the enablers ofpractical software development.”
www.lukas-renggli.ch
He vetia