SlideShare a Scribd company logo
Using Scala for building DSL’s

                         Abhijit Sharma
                         Innovation Lab,
                         BMC Software




                                           1
What is a DSL?
• Domain Specific Language
 • Appropriate abstraction level for domain - uses precise
   concepts and semantics of domain
 • Concise and expressive for a specific domain – not general
   purpose
 • Domain experts can communicate, critique better with
   programmers and amongst themselves
 • Math – Mathematica, UI – HTML, CSS, Database - SQL




                                                                2
DSL’s at large
• Build tool Ant is an XML based
  DSL
   • Task to build a jar with a
     dependency on task compile
• Web App framework Ruby on
  Rails
   • ActiveRecord to model domain
     objects and persist them –
   • Domain constraint
     implementations do not clutter
     API – uniqueness, cardinality,
     null check



                                      3
Cloud Computing DSL
• Audience – Non tech savvy cloud
  end users
• DSL - English language sentence
  for requesting a machine with
  technical and price specifications
• Domain Concept – Machine
   • Technical specifications - cpu,
     os
   • Pricing specifications - spot     Machine

     price, pricing strategy –         •cpu:Cpu
                                       •os:String
     default or define inline          •spotPrice:Int       Cpu

                                                        •arch: String
                                                        •cpus: Int




                                                                        4
Cloud Computing DSL in Java
• Builder pattern - Method Chaining
  Fluent Interface
• Issues
   • Syntax restrictions, verbosity –
     parenthesis, dot, semi-colons
   • Non Domain complexity – Builder
   • No Inline strategy – no higher order
     functions




                                            5
DSL Classification
• Internal DSL
  • Embedded in a host language like Ruby, Scala,
    Groovy – use their features
  • Bound by host language syntax and semantics
• External DSL – standalone developed ground up
  • Define syntax and semantics as a grammar
  • Use tools like lexical analyzers, parsers,
    interpretation, code generators


                                                    6
Internal DSL Classification
• Internal DSL
  • Generative - Ruby, Groovy Techniques like
    runtime metaprogramming
      • Meta Objects – inject new behaviour at runtime
  • Embedded in host language
    • Smart API – Method chaining – Java etc.
    • Syntax tree manipulation – Groovy, Ruby libraries
    • Type Embedding – Scala – statically typed, type
      constraints, no invalid operations on types

                                                         7
Scala Language
• Scala is a “scalable” language
• JVM based – leverage libs, JVM perf,
  tools, install base etc
• Mixed Paradigm – Object Oriented +
  Functional Programming
    • Object Oriented Programming - Improves on Java
      OOP (Traits, no statics, advanced types)



                                                  8
Scala Language
• Functional Programming - Functions
  • No side effects and immutable variables
  • “First-class” citizens - Can be assigned,
    passed around, returned
  • Higher order functions promote composition
    using other more primitive functions
• Lots of powerful features – discussed later
• Statically Typed – Type Safe DSL
                                                9
Scala – Readable style
• Type inference minimizes the
  need for explicit type
  information – still Type safe
• Elegant, succinct syntax
  unlike verbose Java
   • Optional dots, semi-colons and
     parentheses
   • Operators like methods
   • Syntactic sugar method takes
     one/zero argument, drop period
     and parentheses




                                      10
Scala - Implicits
• Implicits
   • Conversions – return a wrapped
     original type e.g. Integer
   • Implicit argument to function –
     don’t need to pass – Concise
     syntax
• Generative expression - Implicit
  conversion converts the 1, an Int, o
  a RichInt which defines a ‘to’
  method
• Lexically scoped – Unlike other
  languages like Groovy where such
  modifications are global in scope


                                         11
Scala - Higher order functions
• Functions which take other
  functions as parameters or
  return them as results are
  called higher-order functions
• Flexible mechanism for
  composition
• Currying




                                  12
Scala – Functional Combinators
• Calculate the total price of all Linux machines – uses
  several combinators – filter, map, foldLeft – all take
  other functions as predicates




                                                       13
Scala – Cloud Computing DSL - Implicits
• Consider excerpt - 8 cpus
  “64bit” – Using Implicit
  conversion we get the object
  representing the CPU - Cpu(8,
  64bit)




                                      14
Scala – Cloud Computing DSL – E2E
DSL - new Machine having (8 cpus
   "64bit") with_os “Linux“
• Implicit Conversion
• Method Chaining – Builder pattern –
  without the cruft
• Syntactic sugar no parenthesis, dot,
  brackets




                                         15
Scala – Cloud Computing DSL – Functions
•   Using Higher Order
    Functions – Flexible pricing
•   Spot Price Threshold - Inline
    strategy




                                          16
Scala - Pattern Matching
• Pattern Matching – Switch
  Case on Steroids
• Cases can include value,
  types, wild-cards, sequences,
  tuples, deep inspection of
  objects




                                  17
Scala - Pattern Matching &Case Classes
• Case Classes – simplified
  construction and can be used
  in pattern matching
• Pattern matching on Case
  Classes
   • Deep pattern matching on
     object contents
   • Make good succinct
     powerful DSL




                                     18
Scala - Pattern Matching – Visitor Pattern
• Pattern match and case
  classes – extensible visitor
• Different operations on tree
   • Expression Evaluation
   • Prefix Notation
• Very expressive, flexible and
  concise code




                                             19
Scala – For Comprehensions
• Loop through Iterable sequences and
  comprehend/compute something
  • E.g. Filter 32, 64 bit architectures




                                           20
Scala – For Comprehensions + Option
• Wrap vars & function returns as
  Option – Null Checks, resilient
  programming
• Option sub classes : None and Some
• Options with for comprehensions,
  automatic removal of None
  elements from comprehensions




                                       21
Scala – For Comprehensions + Option
• Validate and audit
  machines
• Using Options with for
  comprehensions eliminate
  the need for most
  “null/empty” checks.
• Succinct, safe DSL with
  uncluttered API




                                      22
Scala - Traits
•   Traits are collections of fields and
    behaviors that you can extend or mixin
    to your classes.
•   Modularize these concerns, yet enable
    the fine-grained “mixing” of their
    behaviors with other concerns at build
    or run time – Callbacks & Ordered
•   Traits can be mixed-in at class level or
    at instance creation
•   AOP Pervasive concerns - Logging,
    Ordering, Callback Handling




                                               23
External DSL in Scala
DSL - having (8 cpus "64bit") with_os "Linux" at_spot_price 30
• Parser Combinator library – available as a library on host
  language – Scala
• External Parser Generators like Javacc – use tools to
  generate code for tokenizing, parsing
• Parser Combinator Specification is like a BNF grammar




                                                                 24
External DSL in Scala
• Each function is a parser - works on
  a portion of the input, parses it and
  may optionally pass on the
  remaining part to the next parser in
  the chain via the combinator
• Several combinators provided by the
  library like ‘~’ the sequencing
  combinator composes two parsers
  sequentially.
• Optional function application
  combinator (^^) can work, applying
  the function on the result of the
  sequencing combinator.




                                          25
Thanks

   abhijit.sharma@gmail.com
     Twitter : sharmaabhijit
Blog : abhijitsharma.blogspot.com


                                    26

More Related Content

What's hot (19)

PDF
Preparing for Scala 3
Martin Odersky
 
PPTX
Overview of CoffeeScript
Aniruddha Chakrabarti
 
PDF
Scala, Akka, and Play: An Introduction on Heroku
Havoc Pennington
 
PDF
What To Leave Implicit
Martin Odersky
 
PDF
Scalax
Martin Odersky
 
PPT
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
panagenda
 
PPTX
flatMap Oslo presentation slides
Martin Odersky
 
PDF
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp
 
PDF
Java 8 selected updates
Vinay H G
 
PDF
Functional programming in Scala
datamantra
 
PPTX
An Introduction to Scala
Brent Lemons
 
PPTX
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
PPTX
The Road to Lambda - Mike Duigou
jaxconf
 
PPTX
Scala for C# Developers
Omer van Kloeten
 
PPTX
Enterprise Deep Learning with DL4J
Josh Patterson
 
PPT
Devoxx
Martin Odersky
 
PDF
Scala Days NYC 2016
Martin Odersky
 
PDF
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
Preparing for Scala 3
Martin Odersky
 
Overview of CoffeeScript
Aniruddha Chakrabarti
 
Scala, Akka, and Play: An Introduction on Heroku
Havoc Pennington
 
What To Leave Implicit
Martin Odersky
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
panagenda
 
flatMap Oslo presentation slides
Martin Odersky
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp
 
Java 8 selected updates
Vinay H G
 
Functional programming in Scala
datamantra
 
An Introduction to Scala
Brent Lemons
 
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
The Road to Lambda - Mike Duigou
jaxconf
 
Scala for C# Developers
Omer van Kloeten
 
Enterprise Deep Learning with DL4J
Josh Patterson
 
Scala Days NYC 2016
Martin Odersky
 
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 

Viewers also liked (12)

PDF
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Kai Wähner
 
PPTX
Java One - Designing a DSL in Kotlin
Nicolas Fränkel
 
PPT
Java Messaging Service
Dilip Prajapati
 
PDF
The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...
confluent
 
PDF
Integration Patterns for Mission Critical Systems
Angelo Corsaro
 
ODP
Mule integration patterns
himajareddys
 
PDF
Metamorphic Domain-Specific Languages
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PDF
Integration patterns and practices for cloud and mobile computing
SHAKIL AKHTAR
 
PDF
The Data Distribution Service
Angelo Corsaro
 
PDF
Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)
Kai Wähner
 
PDF
JMS - Java Messaging Service
Peter R. Egli
 
PPT
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Kai Wähner
 
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Kai Wähner
 
Java One - Designing a DSL in Kotlin
Nicolas Fränkel
 
Java Messaging Service
Dilip Prajapati
 
The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...
confluent
 
Integration Patterns for Mission Critical Systems
Angelo Corsaro
 
Mule integration patterns
himajareddys
 
Metamorphic Domain-Specific Languages
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Integration patterns and practices for cloud and mobile computing
SHAKIL AKHTAR
 
The Data Distribution Service
Angelo Corsaro
 
Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)
Kai Wähner
 
JMS - Java Messaging Service
Peter R. Egli
 
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Kai Wähner
 
Ad

Similar to Using Scala for building DSLs (20)

PPT
Writing DSL's in Scala
Abhijit Sharma
 
PDF
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
PPTX
AestasIT - Internal DSLs in Scala
Dmitry Buzdin
 
PDF
Scala a case4
lee.gilbert
 
PDF
Getting Started With Scala
Meetu Maltiar
 
PDF
Getting Started With Scala
Xebia IT Architects
 
PPT
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
PDF
Scala Sjug 09
Michael Neale
 
PDF
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
PDF
Software Engineering Thailand: Programming with Scala
Brian Topping
 
PPT
Indic threads pune12-polyglot & functional programming on jvm
IndicThreads
 
PPTX
An Intro to Scala for PHP Developers
HuffPost Code
 
PPTX
All about scala
Yardena Meymann
 
PPTX
Scala adoption by enterprises
Mike Slinn
 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
Building DSLs with Scala
Mohit Jaggi
 
PDF
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
PPTX
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
PDF
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Writing DSL's in Scala
Abhijit Sharma
 
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
AestasIT - Internal DSLs in Scala
Dmitry Buzdin
 
Scala a case4
lee.gilbert
 
Getting Started With Scala
Meetu Maltiar
 
Getting Started With Scala
Xebia IT Architects
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Scala Sjug 09
Michael Neale
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
Software Engineering Thailand: Programming with Scala
Brian Topping
 
Indic threads pune12-polyglot & functional programming on jvm
IndicThreads
 
An Intro to Scala for PHP Developers
HuffPost Code
 
All about scala
Yardena Meymann
 
Scala adoption by enterprises
Mike Slinn
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
Miles Sabin
 
Building DSLs with Scala
Mohit Jaggi
 
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Ad

More from IndicThreads (20)

PPTX
Http2 is here! And why the web needs it
IndicThreads
 
ODP
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
PPT
Go Programming Language - Learning The Go Lang way
IndicThreads
 
PPT
Building Resilient Microservices
IndicThreads
 
PPT
App using golang indicthreads
IndicThreads
 
PDF
Building on quicksand microservices indicthreads
IndicThreads
 
PDF
How to Think in RxJava Before Reacting
IndicThreads
 
PPT
Iot secure connected devices indicthreads
IndicThreads
 
PDF
Real world IoT for enterprises
IndicThreads
 
PPT
IoT testing and quality assurance indicthreads
IndicThreads
 
PPT
Functional Programming Past Present Future
IndicThreads
 
PDF
Harnessing the Power of Java 8 Streams
IndicThreads
 
PDF
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
PPTX
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
PDF
Cars and Computers: Building a Java Carputer
IndicThreads
 
PPTX
Scrap Your MapReduce - Apache Spark
IndicThreads
 
PPT
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
PPTX
Speed up your build pipeline for faster feedback
IndicThreads
 
PPT
Unraveling OpenStack Clouds
IndicThreads
 
PPTX
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 
Http2 is here! And why the web needs it
IndicThreads
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Building Resilient Microservices
IndicThreads
 
App using golang indicthreads
IndicThreads
 
Building on quicksand microservices indicthreads
IndicThreads
 
How to Think in RxJava Before Reacting
IndicThreads
 
Iot secure connected devices indicthreads
IndicThreads
 
Real world IoT for enterprises
IndicThreads
 
IoT testing and quality assurance indicthreads
IndicThreads
 
Functional Programming Past Present Future
IndicThreads
 
Harnessing the Power of Java 8 Streams
IndicThreads
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
Cars and Computers: Building a Java Carputer
IndicThreads
 
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Speed up your build pipeline for faster feedback
IndicThreads
 
Unraveling OpenStack Clouds
IndicThreads
 
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 

Recently uploaded (20)

PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 

Using Scala for building DSLs

  • 1. Using Scala for building DSL’s Abhijit Sharma Innovation Lab, BMC Software 1
  • 2. What is a DSL? • Domain Specific Language • Appropriate abstraction level for domain - uses precise concepts and semantics of domain • Concise and expressive for a specific domain – not general purpose • Domain experts can communicate, critique better with programmers and amongst themselves • Math – Mathematica, UI – HTML, CSS, Database - SQL 2
  • 3. DSL’s at large • Build tool Ant is an XML based DSL • Task to build a jar with a dependency on task compile • Web App framework Ruby on Rails • ActiveRecord to model domain objects and persist them – • Domain constraint implementations do not clutter API – uniqueness, cardinality, null check 3
  • 4. Cloud Computing DSL • Audience – Non tech savvy cloud end users • DSL - English language sentence for requesting a machine with technical and price specifications • Domain Concept – Machine • Technical specifications - cpu, os • Pricing specifications - spot Machine price, pricing strategy – •cpu:Cpu •os:String default or define inline •spotPrice:Int Cpu •arch: String •cpus: Int 4
  • 5. Cloud Computing DSL in Java • Builder pattern - Method Chaining Fluent Interface • Issues • Syntax restrictions, verbosity – parenthesis, dot, semi-colons • Non Domain complexity – Builder • No Inline strategy – no higher order functions 5
  • 6. DSL Classification • Internal DSL • Embedded in a host language like Ruby, Scala, Groovy – use their features • Bound by host language syntax and semantics • External DSL – standalone developed ground up • Define syntax and semantics as a grammar • Use tools like lexical analyzers, parsers, interpretation, code generators 6
  • 7. Internal DSL Classification • Internal DSL • Generative - Ruby, Groovy Techniques like runtime metaprogramming • Meta Objects – inject new behaviour at runtime • Embedded in host language • Smart API – Method chaining – Java etc. • Syntax tree manipulation – Groovy, Ruby libraries • Type Embedding – Scala – statically typed, type constraints, no invalid operations on types 7
  • 8. Scala Language • Scala is a “scalable” language • JVM based – leverage libs, JVM perf, tools, install base etc • Mixed Paradigm – Object Oriented + Functional Programming • Object Oriented Programming - Improves on Java OOP (Traits, no statics, advanced types) 8
  • 9. Scala Language • Functional Programming - Functions • No side effects and immutable variables • “First-class” citizens - Can be assigned, passed around, returned • Higher order functions promote composition using other more primitive functions • Lots of powerful features – discussed later • Statically Typed – Type Safe DSL 9
  • 10. Scala – Readable style • Type inference minimizes the need for explicit type information – still Type safe • Elegant, succinct syntax unlike verbose Java • Optional dots, semi-colons and parentheses • Operators like methods • Syntactic sugar method takes one/zero argument, drop period and parentheses 10
  • 11. Scala - Implicits • Implicits • Conversions – return a wrapped original type e.g. Integer • Implicit argument to function – don’t need to pass – Concise syntax • Generative expression - Implicit conversion converts the 1, an Int, o a RichInt which defines a ‘to’ method • Lexically scoped – Unlike other languages like Groovy where such modifications are global in scope 11
  • 12. Scala - Higher order functions • Functions which take other functions as parameters or return them as results are called higher-order functions • Flexible mechanism for composition • Currying 12
  • 13. Scala – Functional Combinators • Calculate the total price of all Linux machines – uses several combinators – filter, map, foldLeft – all take other functions as predicates 13
  • 14. Scala – Cloud Computing DSL - Implicits • Consider excerpt - 8 cpus “64bit” – Using Implicit conversion we get the object representing the CPU - Cpu(8, 64bit) 14
  • 15. Scala – Cloud Computing DSL – E2E DSL - new Machine having (8 cpus "64bit") with_os “Linux“ • Implicit Conversion • Method Chaining – Builder pattern – without the cruft • Syntactic sugar no parenthesis, dot, brackets 15
  • 16. Scala – Cloud Computing DSL – Functions • Using Higher Order Functions – Flexible pricing • Spot Price Threshold - Inline strategy 16
  • 17. Scala - Pattern Matching • Pattern Matching – Switch Case on Steroids • Cases can include value, types, wild-cards, sequences, tuples, deep inspection of objects 17
  • 18. Scala - Pattern Matching &Case Classes • Case Classes – simplified construction and can be used in pattern matching • Pattern matching on Case Classes • Deep pattern matching on object contents • Make good succinct powerful DSL 18
  • 19. Scala - Pattern Matching – Visitor Pattern • Pattern match and case classes – extensible visitor • Different operations on tree • Expression Evaluation • Prefix Notation • Very expressive, flexible and concise code 19
  • 20. Scala – For Comprehensions • Loop through Iterable sequences and comprehend/compute something • E.g. Filter 32, 64 bit architectures 20
  • 21. Scala – For Comprehensions + Option • Wrap vars & function returns as Option – Null Checks, resilient programming • Option sub classes : None and Some • Options with for comprehensions, automatic removal of None elements from comprehensions 21
  • 22. Scala – For Comprehensions + Option • Validate and audit machines • Using Options with for comprehensions eliminate the need for most “null/empty” checks. • Succinct, safe DSL with uncluttered API 22
  • 23. Scala - Traits • Traits are collections of fields and behaviors that you can extend or mixin to your classes. • Modularize these concerns, yet enable the fine-grained “mixing” of their behaviors with other concerns at build or run time – Callbacks & Ordered • Traits can be mixed-in at class level or at instance creation • AOP Pervasive concerns - Logging, Ordering, Callback Handling 23
  • 24. External DSL in Scala DSL - having (8 cpus "64bit") with_os "Linux" at_spot_price 30 • Parser Combinator library – available as a library on host language – Scala • External Parser Generators like Javacc – use tools to generate code for tokenizing, parsing • Parser Combinator Specification is like a BNF grammar 24
  • 25. External DSL in Scala • Each function is a parser - works on a portion of the input, parses it and may optionally pass on the remaining part to the next parser in the chain via the combinator • Several combinators provided by the library like ‘~’ the sequencing combinator composes two parsers sequentially. • Optional function application combinator (^^) can work, applying the function on the result of the sequencing combinator. 25
  • 26. Thanks [email protected] Twitter : sharmaabhijit Blog : abhijitsharma.blogspot.com 26