NEAL FORD thoughtworker / meme wrangler
ThoughtWorks
14 Wall St, Suite 2019, New York, NY 10005 nford@thoughtworks.com www.nealford.com www.thoughtworks.com memeagora.blogspot.com
ThoughtWorks
building dsls in static & dynamic languages NEAL FORD - - PowerPoint PPT Presentation
Thought Works building dsls in static & dynamic languages NEAL FORD thoughtworker / meme wrangler Thought Works 14 Wall St, Suite 2019, New York, NY 10005 nford@thoughtworks.com www.nealford.com www.thoughtworks.com
NEAL FORD thoughtworker / meme wrangler
ThoughtWorks
14 Wall St, Suite 2019, New York, NY 10005 nford@thoughtworks.com www.nealford.com www.thoughtworks.com memeagora.blogspot.com
ThoughtWorks
ThoughtWorks
ThoughtWorks
groovy java external dsls best practices ruby building dsls in: types of dsls motivation
ThoughtWorks
why won’t everyone shut up already about ruby
why is there so much xml mixed in with my java code? why do things like aspects exist? is there an evolutionary step beyond object-
ThoughtWorks
ThoughtWorks
ThoughtWorks
Superclass Subclass Subclass Subclass Superclass Subclass Subclass Subclass
2.days.from.today
building blocks for dsls
ThoughtWorks
ThoughtWorks
“Route 66, swinging, easy on the chorus, extra solo at the coda, and bump at the end” “Iced Decaf Triple Grande Vanilla Skim with whip latte.” “Scattered, smothered, covered” “OMFG D00d Bob is t3h UBER 1337 R0XX0RZ LOL”
waffle house hash brown language: scattered, smothered, covered, chunked, topped, diced, peppered, & capped
ThoughtWorks
ThoughtWorks
how non-developers talk about work why developers tend to stay within domains all businesses have their own dsl
ThoughtWorks
a limited form of computer language designed for a specific class of problems coined by martin fowler domain specific language general style of development which operates about the idea of building software around a set of domain specific languages language oriented programming
ThoughtWorks
ThoughtWorks
ThoughtWorks
must follow syntax rules aka “embedded” sit atop a base language why dynamic languages tend to make better bases
ThoughtWorks
let your imagination run wild! build your own language must be able to lex and parse your language
ThoughtWorks
ThoughtWorks
treat lines of code as sentences example: jmock expectation
ThoughtWorks
ThoughtWorks
as simple as writing set methods that return this
ThoughtWorks
Make modifier methods return the host object so that multiple modifiers can be invoked in a single expression.
ThoughtWorks
writing a fluent interface around log4j properties file creation
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
wrap existing api’s in fluent interfaces to improve readability example: wrapping ibatis
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
using fluent interface & method chaining
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
when does the call “finish”? how can we make sure things happen at the right time?
ThoughtWorks
chained method calls nested method calls
ThoughtWorks
ThoughtWorks
ThoughtWorks
build fluent interfaces with a mixture of chained and nested method invocations
ThoughtWorks
ThoughtWorks
in the nested add() method
validation building objects with chained methods can create “bad citizens”
imposes order semantics
allows invalid state
ThoughtWorks
ThoughtWorks
dynamic typing closures
looser syntax rules than java
ThoughtWorks
call a new method on String
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
returns a java.util.Calendar for the proper date
ThoughtWorks
4.pm
ThoughtWorks
ThoughtWorks
ThoughtWorks
2 Integer days Integer fromToday Calendar at Calendar 4.pm Integer
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
added an expression builder support for days of the week
ThoughtWorks
array as value
ThoughtWorks
Form language expressions using literal collection syntax
ThoughtWorks
ThoughtWorks
dsl’s allow you to specify intent without coupling in implementation declarative code reveals semantic intent imperative code reveals implementation
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
ThoughtWorks
create your own parser & lexer lex/yacc
www.antlr.org
ThoughtWorks
ThoughtWorks
ThoughtWorks
software factories (microsoft) a tool that supports language oriented programming intentional software (charles simonyi) mps (jetbrains)
ThoughtWorks
class Foo { private int id; . . . . . . }
Editable Representation Storage Representation Executable Representation Parse Compile
ThoughtWorks
ThoughtWorks
first java ide to edit the abstract syntax directly enables refactoring
ThoughtWorks
class Foo { private int id; . . . . . . }
Executable Representation Workbench Versioning Storage Editable Representation Storage Representation
Tab Tab Tab
Document Window
Label
Menu Text Field Text Field Text Field Text Field Text Field Text Field
Label Label
Text Field
Projections
ThoughtWorks
ThoughtWorks
ThoughtWorks
the rake napkin what is the ideal dsl syntax? build towards it
ThoughtWorks
ThoughtWorks
...not creating more complicated languages keep your dsl as cohesive as possible create solutions by composing dsls... jetbrain’s use of mps
ThoughtWorks
http://martinfowler.com/bliki/DomainSpecificLanguage.html
http://www.theserverside.com/news/thread.tss?thread_id=46674
http://martinfowler.com/articles/languageWorkbench.html
http://homepages.cwi.nl/~arie/papers/dslbib/
upcoming book on building internal dsl’s in ruby zak tamsen, jeremy stell-smith, dan manges, neal ford
ThoughtWorks
NEAL FORD thoughtworker / meme wrangler
ThoughtWorks
14 Wall St, Suite 2019, New York, NY 10005 nford@thoughtworks.com www.nealford.com www.thoughtworks.com memeagora.blogspot.com
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 License. http://creativecommons.org/licenses/by-nc-sa/2.5/