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

Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
Martin Odersky
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
Aniruddha Chakrabarti
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Scalax
ScalaxScalax
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
panagenda
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slidesMartin Odersky
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp
 
Ch6
Ch6Ch6
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
datamantra
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
jaxconf
 
Scala for C# Developers
Scala for C# DevelopersScala for C# Developers
Scala for C# Developers
Omer van Kloeten
 
Enterprise Deep Learning with DL4J
Enterprise Deep Learning with DL4JEnterprise Deep Learning with DL4J
Enterprise Deep Learning with DL4J
Josh Patterson
 
Devoxx
DevoxxDevoxx
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
Martin Odersky
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 

What's hot (19)

Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Scalax
ScalaxScalax
Scalax
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slides
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
 
Ch6
Ch6Ch6
Ch6
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Scala for C# Developers
Scala for C# DevelopersScala for C# Developers
Scala for C# Developers
 
Enterprise Deep Learning with DL4J
Enterprise Deep Learning with DL4JEnterprise Deep Learning with DL4J
Enterprise Deep Learning with DL4J
 
Devoxx
DevoxxDevoxx
Devoxx
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 

Viewers also liked

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

Viewers also liked (12)

Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
 
Java One - Designing a DSL in Kotlin
Java One - Designing a DSL in KotlinJava One - Designing a DSL in Kotlin
Java One - Designing a DSL in Kotlin
 
Java Messaging Service
Java Messaging ServiceJava Messaging Service
Java Messaging Service
 
The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...
The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...
The Enterprise Service Bus is Dead! Long live the Enterprise Service Bus, Rim...
 
Integration Patterns for Mission Critical Systems
Integration Patterns for Mission Critical SystemsIntegration Patterns for Mission Critical Systems
Integration Patterns for Mission Critical Systems
 
Mule integration patterns
Mule    integration patternsMule    integration patterns
Mule integration patterns
 
Metamorphic Domain-Specific Languages
Metamorphic Domain-Specific LanguagesMetamorphic Domain-Specific Languages
Metamorphic Domain-Specific Languages
 
Integration patterns and practices for cloud and mobile computing
Integration patterns and practices for cloud and mobile computingIntegration patterns and practices for cloud and mobile computing
Integration patterns and practices for cloud and mobile computing
 
The Data Distribution Service
The Data Distribution ServiceThe Data Distribution Service
The Data Distribution Service
 
Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)
Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)
Microservices - Death of the Enterprise Service Bus (ESB)? (Update 2016)
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
 

Similar to Using Scala for building DSLs

Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
Tomoharu ASAMI
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
John Nestor
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeks
jutley
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQLDon Demcsak
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
Jose Quesada (hiring)
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
Drill architecture 20120913
Drill architecture 20120913Drill architecture 20120913
Drill architecture 20120913jasonfrantz
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
Camuel Gilyadov
 
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
Rainforest QA
 
Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)
Alexey Rybak
 
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...Qian Lin
 
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Scala and Spark are Ideal for Big Data - Data Science Pop-up SeattleScala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Domino Data Lab
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
Manish Pandit
 
Sa introduction to big data pipelining with cassandra & spark west mins...
Sa introduction to big data pipelining with cassandra & spark   west mins...Sa introduction to big data pipelining with cassandra & spark   west mins...
Sa introduction to big data pipelining with cassandra & spark west mins...
Simon Ambridge
 
Transitioning from Java to Scala for Spark - March 13, 2019
Transitioning from Java to Scala for Spark - March 13, 2019Transitioning from Java to Scala for Spark - March 13, 2019
Transitioning from Java to Scala for Spark - March 13, 2019
Gravy Analytics
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
Spark Summit
 

Similar to Using Scala for building DSLs (20)

Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Scala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud PlatformScala in Model-Driven development for Apparel Cloud Platform
Scala in Model-Driven development for Apparel Cloud Platform
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeks
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
Drill architecture 20120913
Drill architecture 20120913Drill architecture 20120913
Drill architecture 20120913
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
 
Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)
 
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
A Survey of Advanced Non-relational Database Systems: Approaches and Applicat...
 
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Scala and Spark are Ideal for Big Data - Data Science Pop-up SeattleScala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
 
Sa introduction to big data pipelining with cassandra & spark west mins...
Sa introduction to big data pipelining with cassandra & spark   west mins...Sa introduction to big data pipelining with cassandra & spark   west mins...
Sa introduction to big data pipelining with cassandra & spark west mins...
 
Transitioning from Java to Scala for Spark - March 13, 2019
Transitioning from Java to Scala for Spark - March 13, 2019Transitioning from Java to Scala for Spark - March 13, 2019
Transitioning from Java to Scala for Spark - March 13, 2019
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 

More from IndicThreads

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

More from IndicThreads (20)

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

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

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 abhijit.sharma@gmail.com Twitter : sharmaabhijit Blog : abhijitsharma.blogspot.com 26