SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Domain Specific Languages
Hiro Yoshioka
March 15th, 2013
Rakuten Tower 2, Shinagawa, Tokyo, Japan
Chapter 4, Internal DSL

•  Unlike	
  external	
  DSLs,	
  you	
  don’t	
  need	
  to	
  learn	
  
   about	
  grammars	
  and	
  language	
  parsing.	
  
•  Constrain	
  –	
  host	
  language	
  expression	
  
   •  Ruby	
  
   •  Lisp	
  
•  fluent	
  interface	
  vs	
  API	
  




                                                                            2
4.1 Fluent and Command-Query APIs

•  Method	
  Chaining	
  
	
  	
   d1	
  =	
  new	
  Disk(150,	
  Disk.UNKNOWN_SPEED,	
  null);	
  
Processor	
  p	
  =	
  new	
  Processor(2,	
  2500,	
  Processor.Type.i386);	
  
Disk	
  
Disk	
  d2	
  =	
  new	
  Disk(75,	
  7200,	
  Disk.Interface.SATA);	
  
return	
  new	
  Computer(p,	
  d1,	
  d2);	
  	
  
	
  
Method	
  Chaining	
  
computer()	
  
	
  .processor()	
  
	
  .cores(2)	
  
	
  .speed(2500)	
  
	
  .i386()	
  	
  
.disk()	
  
	
  .size(150)	
  	
  
.disk()	
  
	
  .size(75)	
  
	
  .speed(7200)	
  
	
  .sata()	
  	
  
.end();	
  	
  
	
  
                                                                                   3
4.1 Fluent and Command-Query APIs

•  Func]on	
  Sequence	
  
computer()	
  
processor();	
  
	
  cores(2);	
  
	
  speed(2500);	
  
	
  i386();	
  	
  
disk();	
  
	
  size(150);	
  	
  
disk();	
  
	
  size(75);	
  
	
  speed(7200);	
  
	
  sata();	
  	
  
	
  




                                     4
4.1 Fluent and Command-Query APIs




                                    5
4.1 Fluent and Command-Query APIs

•  Command-­‐query	
  separa]on	
  
   •  Command:	
  may	
  change	
  state,	
  but	
  not	
  
      return	
  value	
  
   •  Query:	
  does	
  not	
  change	
  state	
  
   •  Name	
  –	
  without	
  context	
  
•  Fluent:	
  Name	
  –	
  context	
  is	
  important	
  




                                                              6
4.2 The Need for a Parsing Layer

•  Expression	
  Builder	
  
   •  input:	
  fluent	
  interface	
  
   •  output:	
  a	
  sequence	
  of	
  command-­‐query	
  API	
  
      •  Seman]c	
  model	
  
•  Separa]ng	
  the	
  Seman]c	
  model	
  from	
  
   Expression	
  Builders	
  
   •  You	
  can	
  test	
  them	
  independently.	
  




                                                                     7
4.3 Using Functions

•  func]on	
  –	
  most	
  successful	
  packaging,	
  (also	
  
   called	
  subrou]ne,	
  procedure,	
  method)	
  
computer();	
  
	
  processor();	
  
	
  	
  cores(2);	
  
	
  	
  speed(2500);	
  
	
  	
  i386();	
  	
  
disk();	
  
	
  size(150);	
  	
  
disk();	
  
	
  size(75);	
  
	
  speed(7200);	
  
	
  sata();	
  	
  
	
  


                                                                   8
4.3 Using Functions
•  Method	
  Chaining	
  and	
  Func]on	
  Sequence	
  
   •  Scope	
  of	
  the	
  func]ons	
  
   •  Func]on	
  Sequence:	
  ensure	
  the	
  func]ons	
  
      resolve	
  properly	
  
      •  global	
  func]on	
  –	
  complica]ng	
  
         namespace	
  and	
  introducing	
  global	
  
         variables	
  for	
  parsing	
  data.	
  
         •  Context	
  Variables	
  
      •  Method	
  Chaining	
  –	
  avoids	
  global	
  
      •  object	
  scoping	
  –	
  avoid	
  globalness,	
  
         extensibility	
  
      •  nested	
  func]on	
  –	
  avoid	
  context	
  
         variables	
  
                                                              9
4.3 Using Functions

                         •  nested	
  func]on	
  
                                 •  combines	
  func]ons	
  by	
  making	
  func]on	
  
                                    calls	
  arguments	
  in	
  higher	
  level	
  func]on	
  
                                    calls.	
  
computer(	
                      •  reflects	
  the	
  logical	
  syntax	
  tree	
  of	
  the	
  DSL	
  
                                 •  change	
  in	
  evalua]on	
  order	
  
	
  processor(	
  
	
  	
  	
  	
  cores(2),	
  
	
  	
  	
  	
  speed(2500),	
  
	
  	
  	
  	
  i386	
  
),	
  
                                 •  “(“,	
  “)”,	
  “,”	
  are	
  explicit.	
  noise	
  –	
  Lisp	
  
	
  disk(	
  
	
  	
  	
  	
  size(150)	
         •  (third(second(first)))	
  **	
  I	
  found	
  typo	
  
	
  ),	
  
disk(	
  
	
  	
  	
  	
  size(75),	
  
	
  	
  	
  	
  speed(7200),	
  
	
  	
  	
  SATA	
  
	
  	
  )	
  
);	
  

                                                                                                          10
4.3 Using Functions

•  nested	
  func]on	
  
   •  the	
  hierarchic	
  structure	
  of	
  the	
  
      configura]on	
  is	
  echoed	
  by	
  the	
  language	
  
      constructs	
  themselves	
  	
  
   •  reflects	
  the	
  logical	
  syntax	
  tree	
  of	
  the	
  DSL	
  
   •  evalua]on	
  order	
  
   •  arguments	
  are	
  iden]fied	
  by	
  posi]on	
  rather	
  
      than	
  name	
  



                                                                            11
4.3 Using Functions

                                  •  hybrid	
  
computer(	
  
                                     •  It	
  uses	
  Func]on	
  Sequence,	
  each	
  computer	
  
	
  	
  processor()	
                   func]on	
  uses	
  Nested	
  Func]on,	
  each	
  
	
  	
  	
  	
  .cores(2)	
  
	
  	
  	
  	
  .speed(2500)	
  
                                        processor	
  and	
  disk	
  is	
  using	
  Method	
  
	
  	
  	
  	
  .type(i386),	
          Chaining.	
  
	
  	
  disk()	
  
	
  	
  	
  	
  .size(150),	
        •  Advantages:	
  	
  
	
  	
  disk()	
                        •  Func]on	
  Sequence:	
  each	
  computer	
  
	
  	
  	
  	
  .size(75)	
  
	
  	
  	
  	
  .speed(7200)	
                 defini]on	
  well	
  separated.	
  
	
  	
  	
  	
  .iface(SATA)	
          •  Nested	
  Func]on:	
  eliminates	
  a	
  Context	
  
);	
  
computer(	
                                    Variable.	
  
	
  	
  processor()	
  
	
  	
  	
  	
  	
  .cores(4)	
  
                                        •  Method	
  Chaining:	
  mul]ple	
  op]onal	
  
);	
                                           arguments	
  
                                                                                           12
4.3 Using Functions

•  hybrid	
  
   •  problems	
  –	
  punctua]onal	
  confusion	
  	
  
      •  comma,	
  periods,	
  semicolons,	
  …	
  




                                                           13
4.4 Literal Collections

•  literal	
  list	
  

-­‐-­‐	
  Java	
  or	
  C#	
  
computer(	
  
	
  processor	
  (...),	
  
	
  disk(...),	
  
	
  disk(...)	
  	
  
);	
  	
  
	
  
-­‐-­‐	
  Ruby	
  
computer	
  [	
  
	
  processor(...),	
  
	
  disk(...),	
  
	
  disk(...)	
  	
  
]	
  	
  
	
  
                                                           14
4.4 Literal Collections

•  literal	
  map	
  
   •  named	
  parameters	
  
   •  symbol	
  
       •  immutable,	
  symbol	
  lookup	
  
       •  :symbol	
  (ruby	
  syntax)	
  
-­‐-­‐	
  Ruby	
  
computer(processor(:cores	
  =>	
  2,	
  :type	
  =>	
  :i386),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  disk(:size	
  =>	
  150),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  disk(:size	
  =>	
  75,	
  :speed	
  =>	
  7200,	
  :interface	
  =>	
  :sata))	
  
	
  
-­‐-­‐	
  Ruby	
  2.0	
  has	
  a	
  keyword	
  arguments	
  	
  
	
  


                                                                                                                                                                  15
4.4 Literal Collections

•  symbol	
  

-­‐-­‐	
  Ruby	
  
computer(processor(:cores	
  =>	
  2,	
  :type	
  =>	
  :i386),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  disk(:size	
  =>	
  150),	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  disk(:size	
  =>	
  75,	
  :speed	
  =>	
  7200,	
  :interface	
  =>	
  :sata))	
  	
  
	
  




                                                                                                                                                                      16
4.5 Using Grammars to Choose Internal
                      Elements
Structure	
                   BNF	
                                                      Consider	
  
Mandatory	
  list	
           parent	
  ::=	
  first	
  second	
  third	
  	
             Nested	
  Func+on	
  (357)	
  	
  
Op]onal	
  list	
  	
  	
     parent	
  ::=	
  first	
  maybeSecond?	
                    Method	
  Chaining	
  (373),	
  
                              maybeThird?	
  	
                                          Literal	
  Map	
  (419)	
  	
  
Homogenous	
  bag	
           parent	
  ::=	
  child*	
  	
                              Literal	
  List	
  (417),	
  	
  
                                                                                         Func+on	
  Sequence	
  (351)	
  	
  
Hetrogenous	
  bag	
  	
      parent	
  ::=	
  (this	
  |	
  that	
  |	
  theOther)*	
  	
   Method	
  Chaining	
  	
  
Set	
  	
                     n/a	
  	
                                                  Literal	
  Map	
  	
  




                                                                                                                                17
4.6 Closures

•  lambdas,	
  blocks,	
  anonymous	
  func]ons	
  

#ruby...	
  
ComputerBuilder.build	
  do	
  |c|	
  
	
  	
  c.processor	
  do	
  |p|	
  
	
  	
  	
  	
  p.cores	
  2	
  
	
  	
  	
  	
  p.i386	
  
	
  	
  	
  	
  p.speed	
  2.2	
  
	
  	
  end	
  
	
  	
  c.disk	
  do	
  |d|	
  
	
  	
  	
  	
  d.size	
  150	
  	
  
	
  	
  end	
  
	
  	
  c.disk	
  do	
  |d|	
  
	
  	
  	
  d.size	
  75	
  
	
  	
  	
  d.speed	
  7200	
  
	
  	
  	
  d.sata	
  
	
  	
  end	
  
end	
  




                                                        18
4.6 Closures
          •  Nested	
  Closures	
  
             •  inline	
  nes]ng	
  
             •  deferred	
  evalua]on	
  
             •  limited-­‐scope	
  variables	
  
#ruby...	
  
ComputerBuilder.build	
  do	
  |c|	
  
	
  	
  c.processor	
  do	
  |p|	
  
	
  	
  	
  	
  p.cores	
  2	
  
	
  	
  	
  	
  p.i386	
  
	
  	
  	
  	
  p.speed	
  2.2	
  
	
  	
  end	
  
	
  	
  c.disk	
  do	
  |d|	
  
	
  	
  	
  	
  d.size	
  150	
  	
  
	
  	
  end	
  
	
  	
  c.disk	
  do	
  |d|	
  
	
  	
  	
  d.size	
  75	
  
	
  	
  	
  d.speed	
  7200	
  
	
  	
  	
  d.sata	
  
	
  	
  end	
  
end	
  


                                                        19
4.7 Parse Tree Manipulation

•  parse	
  tree	
  manipula]on	
  
                                                            4.7 Parse Tree Manipulatio


                                         BinaryExpression


                                          Left          Right


                          MemberAccess              ConstantExpression


                              Member Expression                 Value


                        Age         aPerson                   18


   Figure 4.2 A parse tree representation of aPerson.Age > 18


   query in another query language, such as SQL. This is essentially what 20
                                                                           .NET
4.8 Annotation

•  Auribute	
  in	
  C#	
  

  class	
  Person	
  
  	
  	
  	
  	
  validates_length_of	
  :last_name,	
  :maximum	
  =>	
  30	
  




                                                                                   21
4.9 Literal Extension

•  Method	
  Chaining	
  
•  chain	
  begins	
  on	
  a	
  literal	
  integer,	
  	
  
   e.g.	
  5.days.ago	
  
   •  add	
  methods	
  to	
  external	
  library	
  classes	
  
   •  Cons:	
  methods	
  globally	
  




                                                                   22
4.10 Reducing the Syntactic Noise

•  Textual	
  Polishing	
  




                                       23
4.11 Dynamic Reception

•  handle	
  an	
  unexpected	
  call	
  by	
  run]me	
  to	
  a	
  
   special	
  method.	
  programmers	
  can	
  override	
  
   the	
  method	
  to	
  do	
  other	
  things.	
  
   •  method_missing	
  in	
  Ruby,	
  
   •  doesNotUnderstand	
  in	
  Smalltalk	
  
•  e.g.,	
  Rails	
  Ac]ve	
  record’s	
  dynamic	
  finders	
  




                                                                       24
4.12 Providing Some Type Checking

•  sta]c	
  type	
  checking	
  or	
  not	
  
•  type	
  checking	
  at	
  compile	
  ]me	
  or	
  run	
  ]me	
  
•  modern	
  IDEs	
  provide	
  excellent	
  support	
  based	
  
   on	
  sta]c	
  typing	
  




                                                                      25
Yoshioka	
  
               26

Contenu connexe

Tendances

BIS and COM in Action
BIS and COM in ActionBIS and COM in Action
BIS and COM in ActionJerry Merrill
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB Rakuten Group, Inc.
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomynzhang
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)Qiangning Hong
 
Hanborq Optimizations on Hadoop MapReduce
Hanborq Optimizations on Hadoop MapReduceHanborq Optimizations on Hadoop MapReduce
Hanborq Optimizations on Hadoop MapReduceHanborq Inc.
 
Intro To Cascading
Intro To CascadingIntro To Cascading
Intro To CascadingNate Murray
 
Fuse'ing python for rapid development of storage efficient FS
Fuse'ing python for rapid development of storage efficient FSFuse'ing python for rapid development of storage efficient FS
Fuse'ing python for rapid development of storage efficient FSChetan Giridhar
 
Design of bare metal proxy compute node
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute nodeLorin Hochstein
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Add Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with SolrAdd Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with Solradunne
 
stream processing engine
stream processing enginestream processing engine
stream processing enginetiana528
 
R Jobs on the Cloud
R Jobs on the CloudR Jobs on the Cloud
R Jobs on the CloudJohn Doxaras
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentationMurat Çakal
 
DSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital LibraryDSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital Libraryrajivkumarmca
 
Shark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleShark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleDataWorks Summit
 
Foreign Data Wrapper Enhancements
Foreign Data Wrapper EnhancementsForeign Data Wrapper Enhancements
Foreign Data Wrapper EnhancementsShigeru Hanada
 

Tendances (20)

BIS and COM in Action
BIS and COM in ActionBIS and COM in Action
BIS and COM in Action
 
Apache Spark with Scala
Apache Spark with ScalaApache Spark with Scala
Apache Spark with Scala
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomy
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
 
Hanborq Optimizations on Hadoop MapReduce
Hanborq Optimizations on Hadoop MapReduceHanborq Optimizations on Hadoop MapReduce
Hanborq Optimizations on Hadoop MapReduce
 
Intro To Cascading
Intro To CascadingIntro To Cascading
Intro To Cascading
 
Fuse'ing python for rapid development of storage efficient FS
Fuse'ing python for rapid development of storage efficient FSFuse'ing python for rapid development of storage efficient FS
Fuse'ing python for rapid development of storage efficient FS
 
Design of bare metal proxy compute node
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute node
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Add Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with SolrAdd Powerful Full Text Search to Your Web App with Solr
Add Powerful Full Text Search to Your Web App with Solr
 
stream processing engine
stream processing enginestream processing engine
stream processing engine
 
R Jobs on the Cloud
R Jobs on the CloudR Jobs on the Cloud
R Jobs on the Cloud
 
Dvm
DvmDvm
Dvm
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
 
HiveServer2
HiveServer2HiveServer2
HiveServer2
 
DSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital LibraryDSpace Tutorial : Open Source Digital Library
DSpace Tutorial : Open Source Digital Library
 
Shark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at ScaleShark SQL and Rich Analytics at Scale
Shark SQL and Rich Analytics at Scale
 
Foreign Data Wrapper Enhancements
Foreign Data Wrapper EnhancementsForeign Data Wrapper Enhancements
Foreign Data Wrapper Enhancements
 

Similaire à DSL - Domain Specific Languages, Chapter 4, Internal DSL

Hadoop - Disk Fail In Place (DFIP)
Hadoop - Disk Fail In Place (DFIP)Hadoop - Disk Fail In Place (DFIP)
Hadoop - Disk Fail In Place (DFIP)mundlapudi
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2Gal Marder
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture EMC
 
AltaVista Search Engine Architecture
AltaVista Search Engine ArchitectureAltaVista Search Engine Architecture
AltaVista Search Engine ArchitectureChangshu Liu
 
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
 
Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets  Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets Perforce
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS Chris Harris
 
3 installation-setup-of-r3
3 installation-setup-of-r33 installation-setup-of-r3
3 installation-setup-of-r3sanganiraju
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living DatalogMike Fogus
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017OpenEBS
 
Why Functional Programming Is Important in Big Data Era
Why Functional Programming Is Important in Big Data EraWhy Functional Programming Is Important in Big Data Era
Why Functional Programming Is Important in Big Data EraHandaru Sakti
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Felix Geisendörfer
 
HPTS talk on micro-sharding with Katta
HPTS talk on micro-sharding with KattaHPTS talk on micro-sharding with Katta
HPTS talk on micro-sharding with KattaTed Dunning
 
20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnwgarrett honeycutt
 

Similaire à DSL - Domain Specific Languages, Chapter 4, Internal DSL (20)

Hadoop Overview kdd2011
Hadoop Overview kdd2011Hadoop Overview kdd2011
Hadoop Overview kdd2011
 
Hadoop - Disk Fail In Place (DFIP)
Hadoop - Disk Fail In Place (DFIP)Hadoop - Disk Fail In Place (DFIP)
Hadoop - Disk Fail In Place (DFIP)
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture
 
AltaVista Search Engine Architecture
AltaVista Search Engine ArchitectureAltaVista Search Engine Architecture
AltaVista Search Engine Architecture
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
 
Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)Large-scale projects development (scaling LAMP)
Large-scale projects development (scaling LAMP)
 
Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets  Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
3 installation-setup-of-r3
3 installation-setup-of-r33 installation-setup-of-r3
3 installation-setup-of-r3
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living Datalog
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
 
Why Functional Programming Is Important in Big Data Era
Why Functional Programming Is Important in Big Data EraWhy Functional Programming Is Important in Big Data Era
Why Functional Programming Is Important in Big Data Era
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
mtl_rubykaigi
mtl_rubykaigimtl_rubykaigi
mtl_rubykaigi
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
HPTS talk on micro-sharding with Katta
HPTS talk on micro-sharding with KattaHPTS talk on micro-sharding with Katta
HPTS talk on micro-sharding with Katta
 
20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw
 

Plus de Hiro Yoshioka

Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活
Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活
Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活Hiro Yoshioka
 
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」Hiro Yoshioka
 
不揮発性メモリ(NVM)とはなにか
不揮発性メモリ(NVM)とはなにか不揮発性メモリ(NVM)とはなにか
不揮発性メモリ(NVM)とはなにかHiro Yoshioka
 
続・人生100年時代の学び方
続・人生100年時代の学び方続・人生100年時代の学び方
続・人生100年時代の学び方Hiro Yoshioka
 
人生100年時代における学び方 定年後の学生生活
人生100年時代における学び方 定年後の学生生活人生100年時代における学び方 定年後の学生生活
人生100年時代における学び方 定年後の学生生活Hiro Yoshioka
 
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...Hiro Yoshioka
 
人生100年時代の学び方、脳には可塑性がある
人生100年時代の学び方、脳には可塑性がある人生100年時代の学び方、脳には可塑性がある
人生100年時代の学び方、脳には可塑性があるHiro Yoshioka
 
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7Hiro Yoshioka
 
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演Hiro Yoshioka
 
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】Hiro Yoshioka
 
未経験プログラマがコボルコンパイラを作った話 #compiler_study
未経験プログラマがコボルコンパイラを作った話 #compiler_study未経験プログラマがコボルコンパイラを作った話 #compiler_study
未経験プログラマがコボルコンパイラを作った話 #compiler_studyHiro Yoshioka
 
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12Hiro Yoshioka
 
海外から見た東京 〜人生100年時代の働き方〜 #efsta56
海外から見た東京 〜人生100年時代の働き方〜 #efsta56海外から見た東京 〜人生100年時代の働き方〜 #efsta56
海外から見た東京 〜人生100年時代の働き方〜 #efsta56Hiro Yoshioka
 
理科系の作文技術
理科系の作文技術理科系の作文技術
理科系の作文技術Hiro Yoshioka
 
Agile Software Development advanced course (PBL) at AIIT, 2015
Agile Software Development advanced course (PBL) at AIIT, 2015Agile Software Development advanced course (PBL) at AIIT, 2015
Agile Software Development advanced course (PBL) at AIIT, 2015Hiro Yoshioka
 
質問される力 #TechGirls
質問される力 #TechGirls質問される力 #TechGirls
質問される力 #TechGirlsHiro Yoshioka
 
Oracle vs Google API 著作権裁判を考える
Oracle vs Google API 著作権裁判を考えるOracle vs Google API 著作権裁判を考える
Oracle vs Google API 著作権裁判を考えるHiro Yoshioka
 
Using oss at an internet company and hacker culture
Using oss at an internet company and hacker cultureUsing oss at an internet company and hacker culture
Using oss at an internet company and hacker cultureHiro Yoshioka
 
Project Based Learning using by PaaS
Project Based Learning using by PaaSProject Based Learning using by PaaS
Project Based Learning using by PaaSHiro Yoshioka
 

Plus de Hiro Yoshioka (20)

Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活
Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活
Infra study 2nd #1 人生100年時代の学び方,定年後の大学院生活
 
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」
Infra study 2nd #1「インフラ技術者・研究者としてのキャリア」
 
不揮発性メモリ(NVM)とはなにか
不揮発性メモリ(NVM)とはなにか不揮発性メモリ(NVM)とはなにか
不揮発性メモリ(NVM)とはなにか
 
続・人生100年時代の学び方
続・人生100年時代の学び方続・人生100年時代の学び方
続・人生100年時代の学び方
 
人生100年時代における学び方 定年後の学生生活
人生100年時代における学び方 定年後の学生生活人生100年時代における学び方 定年後の学生生活
人生100年時代における学び方 定年後の学生生活
 
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...
Thesis introduction "RECIPE : Converting Concurrent DRAM Indexes to Persisten...
 
人生100年時代の学び方、脳には可塑性がある
人生100年時代の学び方、脳には可塑性がある人生100年時代の学び方、脳には可塑性がある
人生100年時代の学び方、脳には可塑性がある
 
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、「私のような仕事につく方法」、2019/06/23 DevLOVE X Day 1 D-7
 
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演
OSSとの付き合い方。OSSから学んだこと。OSS貢献者賞受賞講演
 
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】
エンジニア人生と定年退職、人生100年時代のエンジニアの生き方、デブサミ 2019 【15-A-8】
 
未経験プログラマがコボルコンパイラを作った話 #compiler_study
未経験プログラマがコボルコンパイラを作った話 #compiler_study未経験プログラマがコボルコンパイラを作った話 #compiler_study
未経験プログラマがコボルコンパイラを作った話 #compiler_study
 
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12
Godel, Escher, Bach: an Eternal Golden Braid, reading club, Chapter 12
 
海外から見た東京 〜人生100年時代の働き方〜 #efsta56
海外から見た東京 〜人生100年時代の働き方〜 #efsta56海外から見た東京 〜人生100年時代の働き方〜 #efsta56
海外から見た東京 〜人生100年時代の働き方〜 #efsta56
 
理科系の作文技術
理科系の作文技術理科系の作文技術
理科系の作文技術
 
Agile Software Development advanced course (PBL) at AIIT, 2015
Agile Software Development advanced course (PBL) at AIIT, 2015Agile Software Development advanced course (PBL) at AIIT, 2015
Agile Software Development advanced course (PBL) at AIIT, 2015
 
質問される力 #TechGirls
質問される力 #TechGirls質問される力 #TechGirls
質問される力 #TechGirls
 
Oracle vs Google API 著作権裁判を考える
Oracle vs Google API 著作権裁判を考えるOracle vs Google API 著作権裁判を考える
Oracle vs Google API 著作権裁判を考える
 
Using oss at an internet company and hacker culture
Using oss at an internet company and hacker cultureUsing oss at an internet company and hacker culture
Using oss at an internet company and hacker culture
 
Be Hacker
Be HackerBe Hacker
Be Hacker
 
Project Based Learning using by PaaS
Project Based Learning using by PaaSProject Based Learning using by PaaS
Project Based Learning using by PaaS
 

Dernier

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Dernier (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

DSL - Domain Specific Languages, Chapter 4, Internal DSL

  • 1. Domain Specific Languages Hiro Yoshioka March 15th, 2013 Rakuten Tower 2, Shinagawa, Tokyo, Japan
  • 2. Chapter 4, Internal DSL •  Unlike  external  DSLs,  you  don’t  need  to  learn   about  grammars  and  language  parsing.   •  Constrain  –  host  language  expression   •  Ruby   •  Lisp   •  fluent  interface  vs  API   2
  • 3. 4.1 Fluent and Command-Query APIs •  Method  Chaining       d1  =  new  Disk(150,  Disk.UNKNOWN_SPEED,  null);   Processor  p  =  new  Processor(2,  2500,  Processor.Type.i386);   Disk   Disk  d2  =  new  Disk(75,  7200,  Disk.Interface.SATA);   return  new  Computer(p,  d1,  d2);       Method  Chaining   computer()    .processor()    .cores(2)    .speed(2500)    .i386()     .disk()    .size(150)     .disk()    .size(75)    .speed(7200)    .sata()     .end();       3
  • 4. 4.1 Fluent and Command-Query APIs •  Func]on  Sequence   computer()   processor();    cores(2);    speed(2500);    i386();     disk();    size(150);     disk();    size(75);    speed(7200);    sata();       4
  • 5. 4.1 Fluent and Command-Query APIs 5
  • 6. 4.1 Fluent and Command-Query APIs •  Command-­‐query  separa]on   •  Command:  may  change  state,  but  not   return  value   •  Query:  does  not  change  state   •  Name  –  without  context   •  Fluent:  Name  –  context  is  important   6
  • 7. 4.2 The Need for a Parsing Layer •  Expression  Builder   •  input:  fluent  interface   •  output:  a  sequence  of  command-­‐query  API   •  Seman]c  model   •  Separa]ng  the  Seman]c  model  from   Expression  Builders   •  You  can  test  them  independently.   7
  • 8. 4.3 Using Functions •  func]on  –  most  successful  packaging,  (also   called  subrou]ne,  procedure,  method)   computer();    processor();      cores(2);      speed(2500);      i386();     disk();    size(150);     disk();    size(75);    speed(7200);    sata();       8
  • 9. 4.3 Using Functions •  Method  Chaining  and  Func]on  Sequence   •  Scope  of  the  func]ons   •  Func]on  Sequence:  ensure  the  func]ons   resolve  properly   •  global  func]on  –  complica]ng   namespace  and  introducing  global   variables  for  parsing  data.   •  Context  Variables   •  Method  Chaining  –  avoids  global   •  object  scoping  –  avoid  globalness,   extensibility   •  nested  func]on  –  avoid  context   variables   9
  • 10. 4.3 Using Functions •  nested  func]on   •  combines  func]ons  by  making  func]on   calls  arguments  in  higher  level  func]on   calls.   computer(   •  reflects  the  logical  syntax  tree  of  the  DSL   •  change  in  evalua]on  order    processor(          cores(2),          speed(2500),          i386   ),   •  “(“,  “)”,  “,”  are  explicit.  noise  –  Lisp    disk(          size(150)   •  (third(second(first)))  **  I  found  typo    ),   disk(          size(75),          speed(7200),        SATA      )   );   10
  • 11. 4.3 Using Functions •  nested  func]on   •  the  hierarchic  structure  of  the   configura]on  is  echoed  by  the  language   constructs  themselves     •  reflects  the  logical  syntax  tree  of  the  DSL   •  evalua]on  order   •  arguments  are  iden]fied  by  posi]on  rather   than  name   11
  • 12. 4.3 Using Functions •  hybrid   computer(   •  It  uses  Func]on  Sequence,  each  computer      processor()   func]on  uses  Nested  Func]on,  each          .cores(2)          .speed(2500)   processor  and  disk  is  using  Method          .type(i386),   Chaining.      disk()          .size(150),   •  Advantages:        disk()   •  Func]on  Sequence:  each  computer          .size(75)          .speed(7200)   defini]on  well  separated.          .iface(SATA)   •  Nested  Func]on:  eliminates  a  Context   );   computer(   Variable.      processor()            .cores(4)   •  Method  Chaining:  mul]ple  op]onal   );   arguments   12
  • 13. 4.3 Using Functions •  hybrid   •  problems  –  punctua]onal  confusion     •  comma,  periods,  semicolons,  …   13
  • 14. 4.4 Literal Collections •  literal  list   -­‐-­‐  Java  or  C#   computer(    processor  (...),    disk(...),    disk(...)     );       -­‐-­‐  Ruby   computer  [    processor(...),    disk(...),    disk(...)     ]       14
  • 15. 4.4 Literal Collections •  literal  map   •  named  parameters   •  symbol   •  immutable,  symbol  lookup   •  :symbol  (ruby  syntax)   -­‐-­‐  Ruby   computer(processor(:cores  =>  2,  :type  =>  :i386),                                        disk(:size  =>  150),                                        disk(:size  =>  75,  :speed  =>  7200,  :interface  =>  :sata))     -­‐-­‐  Ruby  2.0  has  a  keyword  arguments       15
  • 16. 4.4 Literal Collections •  symbol   -­‐-­‐  Ruby   computer(processor(:cores  =>  2,  :type  =>  :i386),                                        disk(:size  =>  150),                                        disk(:size  =>  75,  :speed  =>  7200,  :interface  =>  :sata))       16
  • 17. 4.5 Using Grammars to Choose Internal Elements Structure   BNF   Consider   Mandatory  list   parent  ::=  first  second  third     Nested  Func+on  (357)     Op]onal  list       parent  ::=  first  maybeSecond?   Method  Chaining  (373),   maybeThird?     Literal  Map  (419)     Homogenous  bag   parent  ::=  child*     Literal  List  (417),     Func+on  Sequence  (351)     Hetrogenous  bag     parent  ::=  (this  |  that  |  theOther)*     Method  Chaining     Set     n/a     Literal  Map     17
  • 18. 4.6 Closures •  lambdas,  blocks,  anonymous  func]ons   #ruby...   ComputerBuilder.build  do  |c|      c.processor  do  |p|          p.cores  2          p.i386          p.speed  2.2      end      c.disk  do  |d|          d.size  150        end      c.disk  do  |d|        d.size  75        d.speed  7200        d.sata      end   end   18
  • 19. 4.6 Closures •  Nested  Closures   •  inline  nes]ng   •  deferred  evalua]on   •  limited-­‐scope  variables   #ruby...   ComputerBuilder.build  do  |c|      c.processor  do  |p|          p.cores  2          p.i386          p.speed  2.2      end      c.disk  do  |d|          d.size  150        end      c.disk  do  |d|        d.size  75        d.speed  7200        d.sata      end   end   19
  • 20. 4.7 Parse Tree Manipulation •  parse  tree  manipula]on   4.7 Parse Tree Manipulatio BinaryExpression Left Right MemberAccess ConstantExpression Member Expression Value Age aPerson 18 Figure 4.2 A parse tree representation of aPerson.Age > 18 query in another query language, such as SQL. This is essentially what 20 .NET
  • 21. 4.8 Annotation •  Auribute  in  C#   class  Person          validates_length_of  :last_name,  :maximum  =>  30   21
  • 22. 4.9 Literal Extension •  Method  Chaining   •  chain  begins  on  a  literal  integer,     e.g.  5.days.ago   •  add  methods  to  external  library  classes   •  Cons:  methods  globally   22
  • 23. 4.10 Reducing the Syntactic Noise •  Textual  Polishing   23
  • 24. 4.11 Dynamic Reception •  handle  an  unexpected  call  by  run]me  to  a   special  method.  programmers  can  override   the  method  to  do  other  things.   •  method_missing  in  Ruby,   •  doesNotUnderstand  in  Smalltalk   •  e.g.,  Rails  Ac]ve  record’s  dynamic  finders   24
  • 25. 4.12 Providing Some Type Checking •  sta]c  type  checking  or  not   •  type  checking  at  compile  ]me  or  run  ]me   •  modern  IDEs  provide  excellent  support  based   on  sta]c  typing   25