SlideShare a Scribd company logo
Domain Specific Languages #DUSE-3
Peter Maas  ~ Developer at Ebay Classifieds, working at the Marktplaats.nl migration. Likes programming languages. whoami
Agenda What is a DSL?
What makes Scala a good language for DSLs
Internal DSL
External DSL ACTUAL CODE!
Questions? Feel free to interrupt!
So, what is a DSL a  D omain- S pecific  L anguage (DSL) is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique.
A language which feels natural to a specialist in the targeted domain
Internal / External Internal DSLs are built using the language itself. Buildr
Gradle
Routing configuration in Apache Camel External DSLs are 'mini' programming languages with their own compiler/interpreter SQL
Velocity
Why is Scala good at that Concise and tolerant syntax
Function objects (closures, currying etc)
Default arguments
Operator overloading
Implicit conversions

More Related Content

What's hot (20)

PPT
eXo SEA - JavaScript Introduction Training
Hoat Le
 
PPTX
Javascript Basics
msemenistyi
 
PDF
TypeScript Introduction
Dmitry Sheiko
 
PDF
Introduction to web programming with JavaScript
T11 Sessions
 
PDF
IO Streams, Files and Directories
Krasimir Berov (Красимир Беров)
 
KEY
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
PPTX
Briefly Rust
Daniele Esposti
 
KEY
Introducing Ruby
James Thompson
 
PPT
Introduction to Javascript
Amit Tyagi
 
PDF
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
jaxLondonConference
 
PDF
Why Haskell
Susan Potter
 
PPTX
Format String
Wei-Bo Chen
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
ODP
How Xslate Works
Goro Fuji
 
PPT
A Deeper look into Javascript Basics
Mindfire Solutions
 
PDF
P6 OO vs Moose (&Moo)
lichtkind
 
PPTX
Clojure 7-Languages
Pierre de Lacaze
 
PDF
Introduction to Ruby
Ranjith Siji
 
PDF
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Javascript Basics
msemenistyi
 
TypeScript Introduction
Dmitry Sheiko
 
Introduction to web programming with JavaScript
T11 Sessions
 
IO Streams, Files and Directories
Krasimir Berov (Красимир Беров)
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
James Thompson
 
Briefly Rust
Daniele Esposti
 
Introducing Ruby
James Thompson
 
Introduction to Javascript
Amit Tyagi
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
jaxLondonConference
 
Why Haskell
Susan Potter
 
Format String
Wei-Bo Chen
 
Class 3 - PHP Functions
Ahmed Swilam
 
How Xslate Works
Goro Fuji
 
A Deeper look into Javascript Basics
Mindfire Solutions
 
P6 OO vs Moose (&Moo)
lichtkind
 
Clojure 7-Languages
Pierre de Lacaze
 
Introduction to Ruby
Ranjith Siji
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 

Viewers also liked (6)

PPT
you
guest0bb81f
 
PDF
Autoforms
jeff kit
 
PDF
Spring MVC introduction HVA
Peter Maas
 
PDF
Introduction To Scala
Peter Maas
 
PDF
Grails @ Battle of the Geeks 2007
Peter Maas
 
PPTX
Introduction to Scala
Rahul Jain
 
Autoforms
jeff kit
 
Spring MVC introduction HVA
Peter Maas
 
Introduction To Scala
Peter Maas
 
Grails @ Battle of the Geeks 2007
Peter Maas
 
Introduction to Scala
Rahul Jain
 
Ad

Similar to Domain Specific Languages In Scala Duse3 (20)

PPTX
Scala 3camp 2011
Scalac
 
PDF
Building DSLs with Scala
Mohit Jaggi
 
PPTX
Scala: the language of languages - Mario Fusco (Red Hat)
Scala Italy
 
PDF
Writing a DSL for the Dense with Scala - JVMCon
Jan-Hendrik Kuperus
 
ODP
Why Scala?
Mike Fogus
 
PPTX
Oscon 2010 Specs talk
Eric Torreborre
 
PDF
Scala Quick Introduction
Damian Jureczko
 
PDF
Free Based DSLs for Distributed Compute Engines
Joydeep Banik Roy
 
PPTX
Scala en
Fero Kocun
 
PPT
Scala introduction
Yardena Meymann
 
PPT
Domain Specific Languages
Wee Witthawaskul
 
PPT
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 
PPT
Implementing External DSLs Using Scala Parser Combinators
Tim Dalton
 
ODP
Scala introduction
Alf Kristian Støyle
 
PPTX
A Brief Intro to Scala
Tim Underwood
 
PDF
Programming in scala - 1
Mukesh Kumar
 
ZIP
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
PPTX
Intro to scala
Joe Zulli
 
PPTX
Why Scala is the better Java
Thomas Kaiser
 
PDF
Generic Functional Programming with Type Classes
Tapio Rautonen
 
Scala 3camp 2011
Scalac
 
Building DSLs with Scala
Mohit Jaggi
 
Scala: the language of languages - Mario Fusco (Red Hat)
Scala Italy
 
Writing a DSL for the Dense with Scala - JVMCon
Jan-Hendrik Kuperus
 
Why Scala?
Mike Fogus
 
Oscon 2010 Specs talk
Eric Torreborre
 
Scala Quick Introduction
Damian Jureczko
 
Free Based DSLs for Distributed Compute Engines
Joydeep Banik Roy
 
Scala en
Fero Kocun
 
Scala introduction
Yardena Meymann
 
Domain Specific Languages
Wee Witthawaskul
 
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 
Implementing External DSLs Using Scala Parser Combinators
Tim Dalton
 
Scala introduction
Alf Kristian Støyle
 
A Brief Intro to Scala
Tim Underwood
 
Programming in scala - 1
Mukesh Kumar
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
Intro to scala
Joe Zulli
 
Why Scala is the better Java
Thomas Kaiser
 
Generic Functional Programming with Type Classes
Tapio Rautonen
 
Ad

Recently uploaded (20)

PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Python basic programing language for automation
DanialHabibi2
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 

Domain Specific Languages In Scala Duse3

  • 2. Peter Maas ~ Developer at Ebay Classifieds, working at the Marktplaats.nl migration. Likes programming languages. whoami
  • 3. Agenda What is a DSL?
  • 4. What makes Scala a good language for DSLs
  • 7. Questions? Feel free to interrupt!
  • 8. So, what is a DSL a D omain- S pecific L anguage (DSL) is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique.
  • 9. A language which feels natural to a specialist in the targeted domain
  • 10. Internal / External Internal DSLs are built using the language itself. Buildr
  • 12. Routing configuration in Apache Camel External DSLs are 'mini' programming languages with their own compiler/interpreter SQL
  • 14. Why is Scala good at that Concise and tolerant syntax
  • 19. Built-in support for building parsers
  • 20. Due to it's functional nature it is good at handling syntax trees.
  • 21. Concise? val toGreet = " Marktplaats developers"  "Hello" . + ( toGreet )   "Hello" + toGreet   "Hello" . concat ( toGreet ) "Hello" concat toGreet   // methods are objects...   val greetMethod = "hello %s".format(_:String) greetMethod(toGreet)
  • 22. Implicit conversions class StringReducer(s:String) { def acronym = s.filter(_.isUpper) } implicit def string2StringReducer(s:String) = new StringReducer(s) "Sun Certified Java Programmer".acronym == "SCJP"
  • 23. Or... case class Route(source:String, target:String) class RouteBuilder(s:String) { def --> (target:String) = Route(s, target) } implicit def string2Route(s:String) = new RouteBuilder(s) "a" --> "b" == Route( "a" , "b" )
  • 24. Let's build a DSL we all know SQL http://github.com/p3t0r/scala-sql-dsl
  • 25. Pure Scala // Simple query with sorting SQL select "*" from ("user") order Asc("name") // More complex query with and/or including precedence SQL select "*" from ("user") where (("name","peter") and (("active", true) or ("role", "admin"))) Overriding the '=' operator was a no-go ;-)
  • 27. case class Where( val clauses: Clause*) trait Clause { def and (otherField: Clause): Clause = And(this, otherField) def or (otherField: Clause): Clause = Or(this, otherField) } case class StringEquals(val f: String, val value: String) extends Clause case class NumberEquals(val f: String, val value: Number) extends Clause case class BooleanEquals(val f: String, val value: Boolean) extends Clause case class In(val field: String, val values: String*) extends Clause case class And(val lClause:Clause, val rClause:Clause) extends Clause case class Or(val lClause:Clause, val rClause:Clause) extends Clause AST for the Where clause
  • 28. Some Implicits & Helpers object QueryBuilder { implicit def tuple2field(t: (String, String)): StringEquals = StringEquals(t._1, t._2) implicit def tuple2field(t: (String, Int)): NumberEquals = NumberEquals(t._1, t._2) implicit def tuple2field(t: (String, Boolean)): BooleanEquals = BooleanEquals(t._1, t._2) implicit def from2query(f: From): Query = Query(f.operation.get, f, Option(Where())) /** entrypoint for starting a select query */ def select(fields:String*) = Select(fields:_*) def select(symbol: Symbol): Select = symbol match { case 'all => select("*") case _ => throw new RuntimeException("Only 'all allowed as symbol") } def in(field: String, values: String*) = In(field, values: _*) }
  • 29. That looks like a lot of code :( The entire builder is only 54 lines, including whitespace and comments! >> CONTINUE IN IDEA <<
  • 30. And external? class SQLParser extends JavaTokenParsers { def query:Parser[Query] = operation ~ from ~ opt(where) ~ opt(order) ^^ { case operation ~ from ~ where ~ order => Query(operation, from, where, order) } def operation:Parser[Operation] = { (&quot;select&quot; | &quot;update&quot; | &quot;delete&quot;) ~ repsep(ident, &quot;,&quot;) ^^ { case &quot;select&quot; ~ f => Select(f:_*) case _ => throw new IllegalArgumentException(&quot;Operation not implemented&quot;) } } def from:Parser[From] = &quot;from&quot; ~> ident ^^ (From(_)) def where:Parser[Where] = &quot;where&quot; ~> rep(clause) ^^ (Where(_:_*)) /* more in idea */ }