Page 1
Programming Modeling
fromto
…and back again
Markus VoelterIndependent/itemis
[email protected]
Page 3
„Houston,we have a
Problem!“
Page 4
Programming Languages
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 5
Programming Languagesare not
enough.expressive
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 6
Programming Languagesare not
enough.high-level
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 7
Programming Languagesare not
enough.abstract
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 8
Programming Languagesare not
enough.domain-specific
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 9
Programming Languagesare notenough.
C# C++ Java
Python
GroovyRubyErlang
CFortran
Page 10
Programming LanguagesFormats
C# C++ Java
Python
GroovyRubyErlang
CFortranHTML
XMLCSSyaml
json
Page 11
Programming LanguagesFormats
C# C++ Java
Python
GroovyRubyErlang
CFortranHTML
XMLCSSyaml
json JEEWPF
Rails
Django
JMS
lift
Frameworks
Page 12
Programming LanguagesFormats
C# C++ Java
Python
GroovyRubyErlang
CFortranHTML
XMLCSSyaml
json JEEWPF
Rails
Django
JMS
lift
Frameworksare not enough.
Page 13
not enough?for what?
Page 14
not enough?for what?
Page 15
not enough?for what?
Page 17
Modeling… Higher Level… Domain Specific
Interpretation… Code Generation
Concepts & Notations
Page 18
Modeling… Higher Level… Domain Specific
Interpretation… Code Generation
Concepts & Notations
Solves theProblem!
Page 20
Modeling Tools Programming Tools
!=
Different Worlds
Page 21
Modeling ToolModeling Tool
!=
Different Worlds
Page 22
Different WorldsMix Models and Programs
Page 23
Different WorldsAST Navigation & Query
Mix Models and Programs
Page 24
Different WorldsAST Navigation & Query
Mix Models and Programs
Integration of 3GL code
Page 25
Different WorldsAST Navigation & Query
Mix Models and Programs
Integration of 3GL codeCode Constraints
Page 28
Domain SpecificNotations
andAbstractions
LibrariesFrameworks
(Fluent) APIs
Flexible! Limited!
Page 29
GraphicalTextual
FormsTables
TextualTrees
Limited!Flexible!
Page 30
CustomizeGenerator
orInterpreter
Limited!Flexible!
ReflectionMeta ProgramsOpen Compilers
Page 31
Define customQueryorNavigate
Limited!Flexible!
AST APIsStatic Analysis
Transformor
Regex
Page 32
CustomValidationorError Checks
Limited!Flexible!
IDE pluginsStatic AnalysisOpen Compilers
Page 33
DifferentRepresentations
andProjections
Limited!Flexible!Text is TextCode FoldingTree ViewsVisualizations
Page 34
Limited!Flexible?Python-to-C-likeInternal DSLs
Mixingand
ComposingLanguages
Embed-As-StringSpecific: LINQ
Page 35
Mature!Brittle!
IDE Support
Scalable
Modeling Tools…!?
Usable
Page 36
Mature!Brittle!
Testing
Debugging
?
Refactoring
Page 37
Mature!Brittle!
Branching
VersioningDiff, Merge
for some tools…
Page 38
Gets theGets some
some people doubt that…
Job Done!Jobs done.everybody agrees…
Page 39
Whythe difference?
Page 41
Modeling Programming
Page 42
Modeling Programming
… (Mostly) Textual Notations
… Concrete Syntax Storage
… (Fancy) ASCII Editors
… Read-Only Visualizations
Page 43
Modeling
… (Mostly) Graphical Notations
… Abstract Syntax Storage
… Projecting Editors
… Different editable views for model
Programming
… (Mostly) Textual Notations
… Concrete Syntax Storage
… (Fancy) ASCII Editors
… Read-Only Visualizations
Page 44
Whythe difference?
Page 46
… a Different Perspective
Page 47
Programmingthe way we do
Modeling?
Modelingthe way we do
Programming?
Page 48
Modeling ProgrammingProgramming Modeling
====
Page 49
We don‘t want to
we want tomodel,
program!
Page 50
We don‘t want to
we want tomodel,
program!… at different levels of abstaction… from different viewpoints… integrated!
Page 51
We don‘t want to
we want tomodel,
program!… with different degrees of
… with suitable notations… with suitable expressiveness
domain-specificity
Page 52
We don‘t want to
we want tomodel,
program!precise and tool processable
And always:
Page 53
Where do we go from here?
Page 54
A vision forprogramming
Page 55
A vision forprogramming
EnablingTechnologies
Page 56
A vision forprogramming
EnablingTechnologies
AvailableTooling
Page 57
A vision forProgramming
Page 58
Programming Languages
are not
enough.MODULAR
Page 59
Programming Languages
are not
enough.COMPOSABLE
Page 60
Programming Languages
are not
enough.CONFIGURABLE
Page 61
Programming Languages
are not
enough.ADAPTABLE
Page 62
Programming Language Syntax
is not
enough.FLEXIBLE
Page 63
L
with many first class concepts!
Big Language?
Page 64
L
Small Language?
and poweful conceptswith a few, orthogonal
Page 65
my L
a b c
d e f
g h i
j k l
Modular Language
composable conceptswith many optional,
Page 66
Like frameworks and libraries,
Modular Language
Page 67
Like frameworks and libraries,
but with syntaxand IDE support
Modular Language
Page 71
Growing A Language(Guy L Steele)
Page 72
LanguageWorkbench
(Martin Fowler)
Page 73
LanguageWorkbench
(Martin Fowler)
Freelydefine
integratethem
languages and
Page 74
?
LanguageWorkbench
(Martin Fowler)
usepersistent
abstractrepresentation
Page 75
LanguageWorkbench
(Martin Fowler)
language ::=schema
editorsgenerators
++
Page 76
?
LanguageWorkbench
(Martin Fowler)
editingprojectional
Page 77
LanguageWorkbench
(Martin Fowler)
persistincompletecontradictory
information
or
Page 78
LanguageWorkbench
(Martin Fowler)
powerfulediting
testingrefactoring
debugging
language definitionIDE definition
implies
+groupware
Page 79
LanguageWorkbench
(Martin Fowler)
support for„classical“
programming„classical“
modelingand+
Page 80
Syntaxprimarilytextual
Page 81
Syntaxprimarilytextual
with more symbolsthink: mathematics
Page 82
Syntaxprimarilytextual
sometimesbox&line style
Page 83
Syntaxprimarilytextual
sophisticatedvisualizations
Page 85
Viewpointssuitableabstractions
notationsfor each
and
Page 86
ViewpointsIntegrated
references
transitions
symbolic
seamlessand
via
Page 87
ViewpointsBusiness
custompurpose-built
create/include
Page 88
ViewpointsCustomNotations
businessexpert integration
real
Business
Page 89
ViewpointsCustomNotations
businessexpert integration
real
Business
But that‘s another talk…
Page 90
ViewpointsTechnical
predefinedlibrary
configure
Page 91
Example Languages
Page 116
matricesAdding
embeddedto C in an
environment.
(Seemingly)
Simple Example
Page 117
Currently:
1 •Declare Data Structures in XML
2 •Generate Headers
3 •Implement manually in C
Page 118
Currently:
Matrices
and generator
not supportedin XML format
Page 119
Currently:
Tool team
… a lot of work
would have todo the extension
… busy… one central tool
Page 120
Currently:
No real
… type checks
compiler supportin the resulting C code
… operator overloading… generics (matrix<int>)… matrix syntax?
Page 123
Better Solution
types
matrixgeneric
vector and
Page 124
Better Solution
matrixreal
literals vector
and
Page 125
Better Solution
highlightssyntax
vectors for
and matrices
Page 126
Better Solution
operator overloading
Page 127
Better Solution
operator overloading
staticoptimization… symmetrical matrices… identity matrix… diagonal matrices
Page 128
Better Solution
math notation
Page 129
Better Solution
used only bythose who
separatea
module language
really need it
Page 131
In addition: PLE Variability
variabilityannotating
expressionsto
arbitrary regions
Page 132
In addition: PLE Variability
variabilityannotating
expressionsto
arbitrary regions
statically checked
Page 133
In addition: PLE Variability
variabilityannotating
expressionsto
arbitrary regions
project variant
Page 135
more later…(tool examples)
Page 138
EnablingTechnologies
Page 139
EnablingTechnologies
AdvancedParser
Generators
Page 140
Modeling as Programmig
… (Mostly) Textual Notations
… Concrete Syntax Storage
… (Fancy) ASCII Editors
… Read-Only Visualizations
Page 141
Custom Syntax
GraphicalTextualSymbolic++
Page 142
IDESupport
TeamworkDebuggingCustom Editors
Page 143
CompleteSymbolicIntegration
Goto DefFind RefsRefactoring
Page 144
Xtext-like Toolsprovide editor support
TeamworkCustom Editors
Goto DefFind Refs
Refactoring
Page 145
UnicodeLimited to
how to handlenon-character symbols
Page 146
TextGraphics !=
two worlds…separate editors… per syntax/viewpoint… models can still be ref integrated
Page 148
What if!combine languagessame seq<Char> as
different tokens?
Page 149
Ambiguous!Not Parsable.
Bad Luck.
Page 150
Traditionally:Language ::=
Token* | Rule*;
Page 151
Traditionally:Language ::=
Token* | Rule*;
Token ::= Character*;
Page 152
Traditionally:Language ::=
Token* | Rule*;
Token ::= Character*;
Rule ::= Token* | Rule;
Page 153
Traditionally:Language ::=
Token* | Rule*;
1. Global Tokenization2. Grammar Recognition
2 Phases:
(aka Scanning)
(aka Parsing)
Page 154
Modern:Language ::=
Rule*;Rule ::= Char* | Rule*;
Grammar Recognition1 Phase:
directly on char*
Page 155
ScannerlessParsing
No Ambiguity
Always Parsable.when combining languages
(well, almost. There are some corner cases…)
Page 157
EnablingTechnologies
ProjectionalEditing
Page 158
Parser-basedtext… to tree… to text
Page 159
Projectionaltree… to text-lookalike (editor)… to other trees … [*]… to text
Page 160
Programming as Modeling
… (Mostly) Graphical Notations
… Abstract Syntax Storage
… Projecting Editors
… Different editable views for model
Page 161
Programming as Modeling
… (Mostly) Graphical Any kind of Notations
… Abstract Syntax Storage
… Projecting Editors
… Different editable views for model
Page 162
Language
There‘s no parsing.
Unique Language Element Identity.
Unlimted language composition.
Composition
Page 163
Textual
Graphical
Semi-Graphical
treated the samecan be mixed
like ASCII }box & line
mathematical
FlexibleNotations
Page 164
AutomaticIDE Extension
tool support is inherentfor languages build with
projectional tools
language definitionIDE definition
implies
Page 165
MultipleNotations
… for the same concepts
e.g. in different contextsor for different tasks
Page 166
PartialProjections
… different views… for different roles/people… only a particular variant
Page 167
Storage!= Schema
… independent of language schema!variability annotations
… store arbitraty meta datachange logconflicting information
… „aspects“, overlay
Page 168
ProgramsLive
think: spreadsheet
a change to one part of programcan lead to (dependent) changesin other parts
Page 169
Tree Editing
… try to make it feel like text
… takes some getting used tobut: for more flexible notations a more general editing paradigm is needed
… is different from editing text
Page 170
InfrastructureIntegration
… diff/merge must be in tool
… existing text tools don‘t work
… storage is not text
Page 171
ProprietaryTools
… no interop
… no standards
Page 173
AvailableTooling
Page 174
AvailableTooling
EclipseXtext
Page 175
http://eclipse.org/modeling
Page 176
http://eclipse.org/xtext
Page 177
Eclipse Xtext
Building Textual Editors
Page 178
Eclipse Xtext
Building Textual Editors
Page 179
Xtext: Specify Grammar
Page 180
Xtext: Gen. Meta Model
Page 181
Xtext: Constraints
Page 182
Xtext: Generated Editor
Page 183
Code Completion
Xtext: Generated Editor
Page 184
Syntax ColoringCustom Keyword Coloring
Xtext: Generated Editor
Page 185
Realtime ConstraintValidation
Xtext: Generated Editor
Page 186
CustomizableOutlines
Xtext: Generated Editor
Page 187
Code FoldingXtext: Generated Editor
Page 188
Goto Definition Find ReferencesCross-File ReferencesModel as EMF
Xtext: Generated Editor
Page 189
Xtext: Generated Editor
Page 191
PlatformArchitecture
DSL
Page 192
As you understandand develop
yourPlatform
Architecture…
Page 193
Develop a language to express it!
Page 194
Language resembles
architectural concepts…
Page 195
Express the applications
with the language.
Page 199
Architecture As LanguageAnother Story…
Page 201
DEMO I
Building DSLs with Eclipse Xtext
Page 203
AvailableTooling
Page 204
AvailableTooling
Jetbrains‘
ProgrammingMeta
System
Page 205
IntelliJ IDEAResharper
also do…
Page 206
Q3 2009released in
1.1 RC1currently
Page 207
Apache 2.0licensed under
Page 208
Build new standalone DSLs
Page 209
Build new standalone DSLsBuild DSLs that reuse parts
of other languages
Page 210
Build new standalone DSLsBuild DSLs that reuse parts
of other languages
(MPS comes with BaseLanguage)extend base language
Java++
Page 211
Build new standalone DSLsBuild DSLs that reuse parts
of other languages
(MPS comes with BaseLanguage)extend base languagebuild DSLs that reuse parts
of BaseLanguage
Java++
Page 212
Java + Extension
Language Extension Example
Page 213
Java
ReadWriteLock l = …l.readLock().lock();try { //code} finally {
l.readLock().unlock();
}
Java + Extension
Language Extension Example
Old
Page 214
Java
ReadWriteLock l = …l.readLock().lock();try { //code} finally {
l.readLock().unlock();
}
Java + Extension
ReadWriteLock l = …lock (l) { //code}
Language Extension Example
Old New
Page 215
Structure Editor Typesystem Generator
Page 216
Structure Editor Typesystem Generator
Page 217
Structure Editor Typesystem Generator
Page 218
Structure Editor Typesystem Generator
Page 219
Structure Editor Typesystem Generator
Page 220
Structure Editor Typesystem Generator
Page 221
Structure Editor Typesystem Generator
Page 222
Structure Editor Typesystem Generator
Page 223
Structure Editor Typesystem Generator
Page 224
Language Extension ExampleResult behaves like a native
base language construct
Page 225
Language Extension ExampleResult behaves like a native
base language construct
Page 226
Language Extension ExampleTranslated to regular Java code
based on the generator
package jaxdemo.sandbox.sandbox;
import java.util.concurrent.locks.Lock;
public class DemoClass {
private Lock lock;
public DemoClass() { try { this.getLock().lock(); SharedResouce.instance().doSomething(); } finally { this.getLock().unlock(); } }
private Lock getLock() { return this.lock; }
}
Page 228
Example LanguagesUI Language
Page 229
Example LanguagesHTML Templates
Page 230
Example LanguagesPersistent Classes
Page 232
DEMO I
Building DSLs with JetBrains MPS
Page 234
AvailableTooling
Page 235
AvailableTooling
Intentional SoftwareDomain
Workbench
Page 237
Dec 15, 2008Version 1.0 released in
currently at 1.4
Page 238
CommercialProduct
Page 239
Eval availableupon request
Page 240
Statemachine ExampleN
ative
Pro
jecti
on
Page 241
Statemachine ExampleTa
bula
r Pro
jecti
on
Page 242
Statemachine ExampleTe
xtua
l DSL
Pro
jecti
on
Page 243
Statemachine ExampleJa
va P
roje
ction
Page 244
Statemachine ExampleRu
by P
roje
ction
Page 245
Statemachine ExampleTw
o pr
ojec
tions
sid
e/si
de
Page 246
Statemachine ExampleTw
o pr
ojec
tions
sid
e/si
de
Page 248
Pension Workbench Example
Text Editing Domain
Page 249
Pension Workbench Example
Insurance Mathematics Domain
Page 250
Pension Workbench Example
Pension Contract Rules Domain
Page 251
Pension Workbench Example
All in one Document
Page 252
Pension Workbench Example
Symbolically integrated
Page 254
A Journey…
Are we there?
Page 255
A Journey…
web email skype
xinglinkedin
[email protected]
http://www.xing.com/profile/Markus_Voelterhttp://www.linkedin.com/pub/0/377/a31
.coordinates