Stéphane Ducasse
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
RMod
Powerful DSL engineering
with Smalltalk
1
S.Ducasse
RMod
A word of introduction
Reflective, metamodeler and happy programmer
Wrote several books on Smalltalk
Pharo by example, Squeak by Example, ...
Pushed Moose
http://www.moosetechnology.org
Building Pharo
http://www.pharo-project.org
Maintained Squeak
http://www.squeak.org
2
S.Ducasse
RMod
RMOD INRIA Team
Software evolution and software composition
Axis 1: Maintaining large software systems
Moose: a platform for reengineering,
http://moosetechnology.com
Axis 2: Modular and Secure Reflective languages
Revisiting fundamental aspects of OO languages
Traits (SUN Microsystems...), Classboxes
Pharo open-source Smalltalk
http://www.pharo-project.org
Starting to work on a secure reflective languages
3
S.Ducasse
RMod
Roadmap
A word about design
Smalltalk an executable modeling language
Internal DSLs industrial examples
Mondrian
Glamour
Seaside
Helvetia: mastering embedded languages
Tools: PetitParser
Conclusion
4
S.Ducasse
RMod
About design and DSL
5
S.Ducasse
RMod
Good OOP design makes implicit explicit
6
S.Ducasse
RMod
Classes structure our vocabulary
7
S.Ducasse
RMod
Classes are recipients of message reaction
8
S.Ducasse
RMod
9
Boolean
xor:
eqv:
storeOn:
and:
or:
ifTrue:ifFalse:
&
not
|
False
and:
or:
ifTrue:ifFalse:
&
not
|
True
and:
or:
ifTrue:ifFalse:
&
not
|
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
self subclassResponsibility
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
^ trueAlternativeBlock value
ifTrue: trueAlternativeBlock ifFalse: falseAlternativeBlock
^ falseAlternativeBlock value
S.Ducasse
RMod
Ternary logic
Boolean: true, false, unknown
10
S.Ducasse
RMod
Focus on **your** domain
Define domain elements as first class objects
Long tradition in Smalltalk
11
S.Ducasse
RMod
Exploratory modeling
Extreme/agile modeling
One domain expert
One developer
Pair-programming with the domain expert
Using the domain expert vocabulary
2007 SAP Experience with Smalltalk
12
S.Ducasse
RMod
Requirements for a real DSL
Adequate syntax
Capture intent/domain
EXECUTABLE!
Tools
TestRunner
Browsers
Semantics versioning
Debuggers!
13
S.Ducasse
RMod
Smalltalk is a modeling executable language
Quite close from xactium
14
S.Ducasse
RMod
Smalltalk
Modeling the world
Simple syntax
Trivial OO model
Executable
Full set of powerful tools
15
S.Ducasse
RMod
A Simple and Pure Model
Everything is an object (no primitive)
Only message passing (virtual)
Public methods/Private attributes
Single inheritance
Class extension (Program slices)
Closures
16
S.Ducasse
RMod
Date today
is a unary message
17
S.Ducasse
RMod
1000 factorial
is a unary message
18
S.Ducasse
RMod
1 / 3
is a binary message
19
S.Ducasse
RMod
1000 factorial / 999 factorial
is a unary/binary messages
20
S.Ducasse
RMod
Color gray - Color white = Color black
21
S.Ducasse
RMod
Color r: 0 g: 0 b: 1
is a keyword-based message
22
S.Ducasse
RMod
From Java to Smalltalk
postman.send(mail,recipient);
23
S.Ducasse
RMod
Removing
postman.send(mail,recipient);
24
S.Ducasse
RMod
Removing unnecessary
postman send mail recipient
25
S.Ducasse
RMod
But without losing information
postman send mail to recipient
26
S.Ducasse
RMod
postman send: mail to: recipient
postman.send(mail,recipient);
27
S.Ducasse
RMod
Tamagotchi
Small entity
Its own night and day cycle
Eating, sleeping, been hungry, been satisfied
Changing color to indicate its mood
28
S.Ducasse
RMod
Class
Object subclass: #Tamagotchi
instanceVariableNames:‘tummy hunger dayCount isNight'
	

 classVariableNames: ''
	

 poolDictionaries: ''
category: ’TOMA'
29
S.Ducasse
RMod
initialize
“Initialize the internal state of a newly created tomagoshi”
super initialize.
tummy := 0.
hunger := 2 atRandom + 1.
self dayStart.
self wakeUp
dayStart
	

night := false.
	

dayCount := 10
30
S.Ducasse
RMod
timePass
"Manage the night and day alternance and digestion"
Beeper beep.
dayCount := dayCount -1.
dayCount isZero
ifTrue:[ self nightOrDayEnd.
	

	

 dayCount := 10].
	

 self digest
digest
"Digest slowly: every two cycle, remove one from the tummy”
(dayCount isDivisibleBy: 2)	

	

 ifTrue: [ tummy := tummy -1]
31
S.Ducasse
RMod
Self-described
32
S.Ducasse
RMod
Implemented totally in itself
extensible...
33
S.Ducasse
RMod
Vocabulary points
34
S.Ducasse
RMod
External Languages
Tools: make, flex, yacc
Data: awk, sed, XPath, Regular Expressions, SQL
+ expressive, full control
- expensive to implement, no tools, hard to pass data around
35
S.Ducasse
RMod
Internal Languages
Ruby: rspec, rake
JavaScript: jQuery
Smalltalk: Mondrian, Seaside, PetitParser
+ easy to implement, tool support, easily mixable
36
S.Ducasse
RMod
Embedded Languages
Language Workbenches: JetBrains MPS, Intentional Software
+ common infrastructure for different languages
- new language, new tools, non-standard host language,
targeted at domain experts (no programmers)
37
S.Ducasse
RMod
Mondrian metaphor: painting a view
Composition with Red,Yellow and Blue
Piet Mondrian (1921)
38
S.Ducasse
RMod
Mondrian a scriptable visualization “language”
fast brainstorming of ideas
interactive
developed by Girba/Meer (SCG, Bern),
maintained, optimized by Bergel (Pleaid, Santiago, Chile)
heavily used by researchers in reengineering
part of Moose
39
S.Ducasse
RMod
The view consists of nodes and edges
view :=ViewRenderer new.
view nodes: classes.
view edges: classes from: [:each | each superclass]
to: [:each | each].
view treeLayout.
view open.
40
S.Ducasse
RMod
Visual representation is given by the shape
view :=ViewRenderer new.
view borderedRectangleShape height: [:each |
each numberOfMethods].
view nodes: classes.
view edges: classes
from: [:each | each superclass]
to: [:each | each].
view treeLayout.
view open.
41
S.Ducasse
RMod
Blocks can be replaced by symbols
view :=ViewRenderer new.
view borderedRectangleShape height:
#numberOfMethods.
view nodes: classes.
view edgesFrom: #superclass.
view treeLayout.
view open.
42
S.Ducasse
RMod
Nesting is done through blocks
view :=ViewRenderer new.
view borderedRectangleShape.
view nodes: classes forEach: [:each |
view nodes: each methods.
view gridLayout].
view edgesFrom: #superclass.
view treeLayout.
view open.
43
S.Ducasse
RMod
What about interaction?
44
S.Ducasse
RMod
Interaction is scriptable, too
view :=ViewRenderer new.
view2 :=ViewRenderer new.
view interaction
onSelect: [:each | each viewOn: view2].
view interaction
popupView: [:each :aView | each viewOn:
aView].
view nodes: ...
45
S.Ducasse
RMod
Glamour
Internal language to build data explorer/browser
Component-based
46
S.Ducasse
RMod
47
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
S.Ducasse
RMod
49
S.Ducasse
RMod
browser := GLMTabulator new.
browser column: #one; column: #two.
browser showOn: #one; using: [
browser table
column: 'Character' evaluated: [ :each | each asString ];
column: 'ASCII' evaluated: [ :each | each asInteger
printString ];
	

 act: [:tree | tree inspect ] on: $i entitled: 'Inspect';
	

 icon: [:x | MenuIcons helpIcon ]].
browser
showOn: #two;
from: #one; using: [ browser text ].
50
S.Ducasse
RMod
Seaside
To build dynamic applications
Applications in production since 2002
Natural Flow
Reusable statefull components
Secure by default
Web 2.0
http://www.seaside.st
51
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
S.Ducasse
RMod
53
S.Ducasse
RMod
value1 := self request:‘first number’.
value2 := self request:‘second number’.
self inform: value1 asNumber + value2
asNumber
54
S.Ducasse
RMod
55
Not concerned about HTTP
No manual request parsing
No XML configuration files
S.Ducasse
RMod
Source:stock.xchng,AlNakib
56
S.Ducasse
RMod
html div id:‘list’; with: [
html span class:‘item’; with:‘Item 1’.
html span class:‘item’; with:‘Item 2’ ]
generates...
<div id=”list”>
<span class=”item”>Item 1</span>
<span class=”item”>Item 2</span>
</div>
57
S.Ducasse
RMod
html anchor
	

 callback: [ self inform:‘Hello World’ ];
	

 with:‘Show Message’
Generates...
<a href=”/seaside/example1
	

 ?_s=Ru8ZKgqjy0uDX3kf
	

 &_k=K5EQyqKE
	

 &32”>Show Message</a>
58
S.Ducasse
RMod
59
S.Ducasse
RMod
WAComponent subclass: #Example2
	

 instanceVariableNames: 'english'
	

 classVariableNames: ''
	

 poolDictionaries: ''
	

 category: 'SeaExample'
60
S.Ducasse
RMod
renderContentOn: html
	

 html form: [
	

 	

 html button
	

 	

 	

 callback: [english := true];
	

 	

 	

 text: 'english'.
	

 	

 html button
	

 	

 	

 callback: [self inFrench];
	

 	

 	

 text: 'french'.
	

 	

 html submitButton
	

 	

 	

 callback: [ english
	

 	

 	

 	

 	

 	

 ifFalse: [self inform: 'Bonjour']
	

 	

 	

 	

 	

 	

 ifTrue: [self inform: 'Hello'] ] ;
	

 	

 	

 text: 'Say Hello' ]
61
S.Ducasse
RMod
Full hot on the fly debug
Full integration with javascript
Handling of the back button
...
62
S.Ducasse
RMod
Slime
Rule for checking validation of Seaside internal
language
63
S.Ducasse
RMod
Mastering Embedded Languages
64
!" #"$%&
S.Ducasse
RMod
65
S.Ducasse
RMod
change semantics
introduce new syntax
change syntax & semantics
66
Adopt, Extend, Overload
Package Name
x = 1
y = 1 (2, 1)
(2, 2)(1, 2)
x = 2
y = 2
S.Ducasse
RMod
aBuilder row grow.
aBuilder row fill.
aBuilder column grow.
aBuilder column fill.
aBuilder x: 1 y: 1 add: (LabelShape new
	

 text: [ :each | each name ];
	

 borderColor: #black;
	

 borderWidth: 1;
	

 yourself).
aBuilder x: 1 y: 2 w: 2 h: 1 add: (RectangleShape new
	

 borderColor: #black;
	

 borderWidth: 1;
	

 width: 200;
Package Name
x = 1
y = 1 (2, 1)
(2, 2)(1, 2)
x = 2
y = 2
68
S.Ducasse
RMod
row = grow.
row = fill.
column = grow.
column = fill.
(1 , 1) = label
	

 	

 text: [ :each | each name ];
	

 	

 borderColor: #black;
	

 	

 borderWidth: 1.
(1 , 2) - (2 , 1) = rectangle
	

 	

 borderColor: #black;
	

 	

 borderWidth: 1;
	

 	

 width: 200;
	

 	

 height: 100.
Package Name
x = 1
y = 1 (2, 1)
(2, 2)(1, 2)
x = 2
y = 2
69
S.Ducasse
RMod
shape {
	

 cols: #grow, #fill;
	

 rows: #grow, #fill;
}
label {
	

 position: 1 , 1;
	

 text: [ :each | each name ];
	

 borderColor: #black;
	

 borderWidth: 1;
}
rectangle {
	

 position: 1 , 2;
	

 colspan: 2;
	

 borderColor: #black;
	

 borderWidth: 1;
	

 width: 200;
Package Name
x = 1
y = 1 (2, 1)
(2, 2)(1, 2)
x = 2
y = 2
70
S.Ducasse
RMod
Homogeneous Tools
71
S.Ducasse
RMod
Domain-Specific
72
Traditional Smalltalk Compiler
Smalltalk
Parser
Semantic
Analysis
Bytecode
Generation
Executable
Code
Source
Code
Traditional Smalltalk Compiler
Smalltalk
Parser
Semantic
Analysis
Bytecode
Generation
Executable
Code
Source
Code
<parse> <transform> <attribute> <bytecode>
Rules
Traditional Smalltalk Compiler
Smalltalk
Parser
Semantic
Analysis
Bytecode
Generation
Executable
Code
Source
Code
<parse> <transform> <attribute> <bytecode>
Rules
<complete> <highlight>
......
Traditional Smalltalk Compiler
Smalltalk
Parser
Semantic
Analysis
Bytecode
Generation
Executable
Code
Source
Code
<parse> <transform> <attribute> <bytecode>
Rules
Pidgin path
Creole path
<complete> <highlight>
......
S.Ducasse
RMod
Scannerless Parsers combine what is usually done by two independent tools
(scanner and parser) into one. This makes writing a grammar much simpler and
avoids common problems when grammars are composed.
Parser Combinators are building blocks for parsers modeled as a graph of composable
objects; they are modular and maintainable, and can be changed, recomposed,
transformed and reflected upon.
Parsing Expression Grammars (PEGs) provide ordered choice. Unlike in parser
combinators, the ordered choice of PEGs always follows the first matching alternative
and ignores other alternatives. Valid input always results in exactly one parse-tree, the
result of a parse is never ambiguous.
Packrat Parsers give linear parse time guarantees and avoid common problems with
left-recursion in PEGs.
77
S.Ducasse
RMod
BNF
ID ::= letter { letter | digit } ;
Ometa2
id = letter (letter | digit)*
PetitParser
id := #letter asParser ,
! (#letter asParser / #digit asParser) star
78
S.Ducasse
RMod
Smalltalk is a serious player in DSL
Trivial model
Trivial syntax
Internal DSLs
Embedded DSLs
Full tool support
Extensible (build your own)
Executable
79
S.Ducasse
RMod
80

More Related Content

PPT
8 - OOP - Smalltalk Syntax
PDF
SoSPa: A System of Security Patterns for engineering Secure Systems
PPT
Software System Engineering - Chapter 11
PDF
Short Gamestop
PPT
Security patterns and model driven architecture
PDF
A Systematic Review of Model-Driven Security
PDF
Integration patterns and practices for cloud and mobile computing
PPTX
J2ee architecture
8 - OOP - Smalltalk Syntax
SoSPa: A System of Security Patterns for engineering Secure Systems
Software System Engineering - Chapter 11
Short Gamestop
Security patterns and model driven architecture
A Systematic Review of Model-Driven Security
Integration patterns and practices for cloud and mobile computing
J2ee architecture

Similar to Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk (20)

PPT
Stoop 305-reflective programming5
PDF
Pharo - I have a dream @ Smalltalks Conference 2009
PPT
Stoop 423-smalltalk idioms
PPT
4 - OOP - Taste of Smalltalk (Tamagoshi)
PDF
Ducasse's Maintenance Expertise
PPT
Stoop sed-smells
PDF
20080115 04 - La qualimétrie pour comprendre et appréhender les SI
PPT
7 - OOP - OO Concepts
PPTX
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
KEY
A tour on ruby and friends
PPT
Stoop 390-instruction stream
KEY
Pharo, an innovative and open-source Smalltalk
PDF
2015 Pharo Prague Lambda Meetup
PDF
Bhavesh ro r
PDF
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
PDF
A Java Developers first Clojure project
PDF
API Platform: A Framework for API-driven Projects
PDF
IJTC%202009%20JRuby
Stoop 305-reflective programming5
Pharo - I have a dream @ Smalltalks Conference 2009
Stoop 423-smalltalk idioms
4 - OOP - Taste of Smalltalk (Tamagoshi)
Ducasse's Maintenance Expertise
Stoop sed-smells
20080115 04 - La qualimétrie pour comprendre et appréhender les SI
7 - OOP - OO Concepts
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
A tour on ruby and friends
Stoop 390-instruction stream
Pharo, an innovative and open-source Smalltalk
2015 Pharo Prague Lambda Meetup
Bhavesh ro r
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
A Java Developers first Clojure project
API Platform: A Framework for API-driven Projects
IJTC%202009%20JRuby
Ad

More from CHOOSE (14)

PPTX
Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
PDF
Continuous Architecting of Stream-Based Systems
PPTX
Modelling and Programming: Isn&rsquo;t it all the same?
PDF
Practical Models in Practice
PDF
Services and Models in a Large IT System
PDF
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
PDF
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
PDF
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
PDF
Ralph Jocham The Risks Of Scrum Handout
PDF
Ralph Jocham The Risks Of Scrum
PDF
Denker - Pharo: Present and Future - 2009-07-14
PPT
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
PPT
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
PDF
2008 02 01 Zeller
Dissecting State-of-the-Art Android Malware Using Static and Dynamic Analysis
Continuous Architecting of Stream-Based Systems
Modelling and Programming: Isn&rsquo;t it all the same?
Practical Models in Practice
Services and Models in a Large IT System
Choose'10: Uwe Zdun - Compliance in service-oriented architectures: A model-d...
Choose'10: Jean-Marie Favre - Domain and Technique Specific Languages – A Jou...
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Ralph Jocham The Risks Of Scrum Handout
Ralph Jocham The Risks Of Scrum
Denker - Pharo: Present and Future - 2009-07-14
Hausi Müller - Towards Self-Adaptive Software-Intensive Systems
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
2008 02 01 Zeller
Ad

Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk