• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Domain Specific Languages
 

Domain Specific Languages

on

  • 7,126 views

Domain Specific Languages presentation to NJUG3 on 22 July 2007

Domain Specific Languages presentation to NJUG3 on 22 July 2007

Statistics

Views

Total Views
7,126
Views on SlideShare
6,576
Embed Views
550

Actions

Likes
8
Downloads
234
Comments
0

9 Embeds 550

http://weerasak.com 466
http://blog.jaffamonkey.com 38
http://www.slideshare.net 28
http://www.techgig.com 6
http://www.linkedin.com 6
http://webcache.googleusercontent.com 3
http://209.85.175.132 1
http://www.google.co.th 1
https://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Domain Specific Languages Domain Specific Languages Presentation Transcript

    • Domain Specific Language Dr. Weerasak Witthawaskul “ Mr. SweetCorn” (weerasak@hotmail.com) Narisa.com’s NJUG Meeting #3 22 July 2007
    • Who am I?
      • oop guy (Pantip)
      • SweetCorn (narisa.com)
      • Wee (weerasak.com)
      • UIUC – Home of Illiac, Transistor, Superconductivity, Mosaic, Paypal, YouTube, Design Patterns, Refactoring
      • Motorola Labs, Schuamburg IL
      • ThoughtWorks Inc., Chicago IL
    • Graduate Life
    • Programming Paradigm Shifts
      • Domain Specific Languages
      • Generative Programming
      • Model Driven Architecture (MDA) - OMG
      • Intentional Programming – Charles Simonyi, ex-Microsoft
      • Language Oriented Programming – Sergey Dmitriev, JetBrains (Home of IntelliJ IDEA)
      • Software Factories – Jack Greenfield, Microsoft
    • What is DSL?
      • “ วันนี้มีประชุมนริสาดอทคอม ”
      • ภาษาไทย
      • “ ทำตัวติสตดีนักถูกแมวีนมายังทำตัวชิวชิวอยู่อีก ...”
      • ภาษาไทยเด็กแนว (domain specific)
    • What is DSL?
      • Mini-language to solve specific “domain” problem
      • Why is it important?
        • SQL – Relational Database Manipulation Language
      • Domain specific vs General purpose
      • What constitutes “domain specific” in programming languages?
    • Mini Game
      • “ What languages are they?”
      • Are they languages for specific domains?
      • From http://www.ntecs.de/old-hp/uu9r/lang/html/lang.en.html
    • What Languages are they?
      • #include <stdio.h>
      • main() {
      • printf(&quot;Hello World &quot;);
      • }
      • C
    • What Languages are they?
      • .MODEL tiny
      • .CODE
      • ORG 100h
      • HELLO PROC
      • MOV AH,09h
      • LEA DX,msg
      • INT 21h ;Display Hello World
      • MOV AX,4C00h ;Exit to DOS
      • INT 21h
      • HELLO ENDP
      • msg DB 'Hello World$'
      • END HELLO
      • Assembly Language Intel 80x86 (DOS/MASM)
    • What Languages are they?
      • <?php
      • echo &quot;Hello World &quot;;
      • ?>
      • PHP
    • What Languages are they?
      • public class HelloWorld {
      • public static void main(String[] args)
      • System.out.println(&quot;Hello World&quot;);
      • }
      • }
      • Java
      • How about JME? JEE?
    • What Languages are they?
      • PROGRAM HelloWorld;
      • BEGIN
      • WRITELN('Hello World');
      • END.
      • PASCAL
    • What Languages are they?
      • print &quot;Hello World&quot;
      • PRINT “Hello World”
      • Basic, Python, Ruby, Perl
    • What Languages are they?
      • SELECT 'Hello World'
      • SQL
    • What Languages are they?
      • BEGIN
      • DBMS_OUTPUT.put_line('Hello World');
      • END;
      • PL/SQL
    • What Languages are they?
      • Report Hello_World.
      • Write: &quot;Hello World&quot;.
      ABAP
    • What Languages are they?
      • io:fwrite(&quot;Hello World~n&quot;).
      Erlang
    • What Languages are they?
      • IDENTIFICATION DIVISION.
      • PROGRAM-ID. HelloWorld.
      • AUTHOR. Fabritius.
      • ENVIRONMENT DIVISION.
      • CONFIGURATION SECTION.
      • INPUT-OUTPUT SECTION.
      • DATA DIVISION.
      • FILE SECTION.
      • WORKING-STORAGE SECTION.
      • LINKAGE SECTION.
      • PROCEDURE DIVISION. DISPLAY &quot;Hello World&quot;. STOP RUN.
      COBOL
    • What Languages are they?
      • % Hello World
      • /Courier findfont
      • 28 scalefont
      • setfont
      • 0 0 moveto
      • (Hello World) show
      • showpage
      • Postscript
    • What Languages are they?
      • /(?ms)&quot;((?>[^amp;quot;]+)?(?>[^amp;quot;]*)*)/
      • Regex – Regular Expression
    • What Languages are they?
      • describe ArticlesController, &quot; GET index&quot; do
      • it &quot;should be successful&quot; do
      • get &quot;index&quot;
      • response.should be_success
      • end
      • if &quot;should set @articles&quot; do
      • Article.should_receive(:find).and_return(mock('articles'))
      • get &quot;index&quot;
      • assigns[:articles].should_not be_nil
      • end
      • RSpec on Ruby - Language of testing from TDD to BDD
    • What Languages are they?
      • >gi|2501594|sp|Q57997|Y577_METJA PROTEIN MJ0577MSVMYKKILYPTDFSETAEIALKHVKAFKTLKAEEVILLHVIDEREIKKRDIFSLLLGVAGLNKSVEEFENELKNKLTEEAKNKMENIKKELEDVGFKVKDIIVVGIPHEEIVKIAEDEGVDIIIMGSHGKTNLKEILLGSVTENVIKKSNKPVLVVKRKNS
      • BLAST query
    • What Languages are they?
      • aspect VisitAspect {
        • void Point.acceptVisitor(Visitor v) {
          • v.visit(this);
        • }
      • }
      • AspectJ
    • What Languages are they?
      • <!--ADVISOR-->
      • <bean id=&quot; theCuckoosEggAdvisor &quot; class=&quot;org.springframework.aop.support.RegexpMethodPointcutAdvisor&quot;>
      • <property name=&quot;advice&quot;>
      • <ref local=&quot; theReplacementFeaturePart1Advice &quot;/> </property>
      • <property name=&quot;pattern&quot;> <value> IBusinessLogic.* </value>
      • </property>
      • </bean>
      • <!--ADVICE-->
      • <bean id=&quot; theReplacementFeaturePart1Advice &quot; class=&quot; CuckoosEgg &quot;/>
      • SpringAOP
    • What Languages are they?
      • <html>
      • <head>
      • <title>Hello World</title>
      • </head>
      • <body>
      • Hello World
      • </body>
      • </html>
      • Of course – HTML!
    • What is DSL?
      • No standard definition
        • Specific vs General depends on point of view
        • VB vs VBA
      • It helps revealing intentions
        • Language that domain experts understand
      • It becomes more and more popular because of tooling support
        • You can apply DSLs to solve your problems
        • You can even create your own DSL!
    • DSL Examples Telecom Adhersion Business Natural Language BNL Pattern Matching Regex Object Relational Mapping Hibernate Publishing Postscript Database Manipulation SQL Domain DSL
    • DSL – Telecom App Framework Adhearsion (open source telecom application framework) + Asterisk (open source telephony platform)
    • LEL – Layout Expression Language
      • layout = &quot; [ label_1 | label3 ]
      • [ (300,300)*text1 | (150)people ]
      • [ <label2 | _ ]
      • [ message | buttons ] &quot;
      Source: http://pphetra.blogspot.com/2007/07/lel.html
    • When to justify DSL
      • Repeated need of solutions to particular problems
      • You have a good understanding of problem domain
      • There is a ready-to-use DSL in that domain
      • Or if you have to invent one…
        • What should it look like?
    • Example - Coffee Order DSL
      • Starbucks Coffee Order (*)
      • “ Venti half-caf, non-fat, no foam, no whip latte”
      • Traditional Implementation
      (*) Agile DSL Development in Ruby – Obie Fernandez (http://obiefernandez.com)
    • Problems with the example
      • Depends on APIs
      • Code does not match the way the domain is described
      • Still difficult to read and verify
    •  
    • DSL style
      • Reveal intention better
      • Take advantage of Ruby features
        • Untyped declaration
        • No parenthesis parameter
        • Metaprogramming support i.e. create class methods on the fly etc.
    • Coffee Order DSL in Java
      • API approach
      • CoffeeOrder order = new Latte(VENTI, HALF_CAF, NONFAT_MILK);
      • CoffeeOrder coffee = order.prepare(false);
      • DSL approach
      • CoffeeOrder order = new Latte().size(VENTI).caffeine(HALF).milk(NONFAT).foam(FALSE);
      • CoffeeOrder coffee = order.prepare();
    • How about other representations?
      • XML
      • <Order type=“Latte”>
      • <caffeine>half</caffeine>
      • <milk>nonfat</milk>
      • <foam>false</form>
      • <whip>false</whip>
      • </Order>
      • English
      • “ Venti half-caf, non-fat, no foam, no whip latte”
      • “ Venti latte with no whip cream, no foam, non-fat milk, half-caffeine”
    • Types of DSL
      • Internal DSL
        • Use an existing “host” programming language to describe DSL
        • Leverage host compiler/interpreter
        • Some programming languages are better for describing DSL e.g. dynamic languages; some use metaprogramming / annotations
      • External DSL
        • Define your own format of the language
        • Use XML along with XSD or DTD
        • Must create your own parser/interpreter
        • Or use DSL tools
    • External DSL
      • Business Natural Language (BNL)
      • “ exclude offer 30 percent cli if d score is less than or equal to 2”
      • Custom DSL
      • show us-state field when country select box is &quot;United States&quot;
      • show province field when country select box is &quot;Canada&quot;
      • show brutus when us-state select box is &quot;Ohio&quot; or &quot;Michigan&quot;
    • DSL Design
      • DSL is not just API
      • show us-state field when country select box is &quot;United States&quot;
      • show province field when country select box is &quot;Canada&quot;
      • show brutus when us-state select box is &quot;Ohio&quot; or &quot;Michigan&quot;
      • JavaScript Solution #1
      • create_dynamic_field(&quot;show&quot;, &quot;us-state-field&quot;, &quot;country&quot;, &quot;United States&quot;);
      • create_dynamic_field(&quot;show&quot;, &quot;province-field&quot;, &quot;country&quot;, &quot;Canada&quot;);
      • create_dynamic_field(&quot;show&quot;, &quot;brutus&quot;, &quot;state&quot;, [&quot;Ohio&quot;, &quot;Michigan&quot;]);
      • JavaScript Solution #2
      • show(&quot;us-state-field&quot;).when(&quot;country&quot;).is(&quot;United States&quot;);
      • show(&quot;province-field&quot;).when(&quot;country&quot;).is(&quot;Canada&quot;);
      • show(&quot;brutus&quot;).when(&quot;us-state&quot;).is(&quot;Ohio, Michigan&quot;);
    • DSL Tools
      • Martin Fowler coined the term “Language Workbench”
      • Provide GUI frontend, metamodeling and/or code generation to define and use DSL
        • Microsoft DSL tool for Visual Studio
        • Intentional Software
        • Eclipse EMF
        • JetBrains Meta Programing System
    • MS DSL Tool for VS Studio Tutorial: Applying Domain-Specific Modeling to Game Development with the Microsoft DSL Tools. André W. B. Furtado, André L. de M. Santos
    • Metacase’s MetaEdit+ http://www.metacase.com/fs.asp?vasen=vasen.html&paa=cases/dsm_examples.html
    • Jetbrains Meta Programming System (MPS)
    • Summary
      • DSL is one way to increase a level of abstraction
        • DSL developers define syntax and semantics to express solutions closer to the domain problem
          • Using DSL tools
          • Creating parser/interpreter
          • Embedding to host languages
        • DSL users can be either programmers or domain experts
    • Summary
      • Types of DSL
        • Internal DSL
          • People start to use dynamic languages to create DSL
            • Ruby on Rails/Grails, Rake (Make on Ruby)
        • External DSL
      • Design is important
        • Consult with domain experts
    • Further Information
      • Wikipedia’s DSL http://en.wikipedia.org/wiki/Domain-specific_programming_language
      • Martin Fowler’s Bliki on DSL http://martinfowler.com/bliki/dsl.html
      • Language Workbenches: The Killer-App for Domain Specific Languages? http://martinfowler.com/articles/languageWorkbench.html
      • Obie Fernandez’s Agile DSL Development in Ruby (http://obiefernandez.com/presentations/obie_fernandez-agile_dsl_development_in_ruby.pdf)
      • Sergey Dmitriev’s Language Oriented Programming: The Next Programming Paradigm (www.onboard.jetbrains.com/is1/articles/04/10/lop/mps.pdf)
    • Q&A Thai’s resources Narisa.com’s Design & Analysis forum ThaiDev.org
    • Backup slides
    • LEL Sample – JRuby
      • require 'profligacy/swing‘
      • require 'profligacy/lel‘
      • module Test
      • include_package 'javax.swing'
      • include Profligacy
      • layout = &quot; [ label_1 | label3 ]
      • [ (300,300)*text1 | (150)people ]
      • [ <label2 | _ ]
      • [ message | buttons ] &quot;
      • ui = Swing::LEL.new(JFrame,layout) do |c,i|
      • c.label_1 = JLabel.new &quot;The chat:&quot;
      • c.label2 = JLabel.new &quot;What you're saying:&quot;
      • c.label3 = JLabel.new &quot;The people:&quot;
      • c.text1 = JTextArea.new
      • c.people = JComboBox.new
      • c.message = JTextArea.new
      • c.buttons = Swing::LEL.new(JPanel, &quot;[send|hate|quit]&quot;) do |c,i|
      • c.send = JButton.new &quot;Send&quot;
      • c.hate = JButton.new &quot;Hate&quot;
      • c.quit = JButton.new &quot;Quit&quot;
      • end.build :auto_create_container_gaps => false
      • end
      • ui.build(:args => &quot;Simple LEL Example“)
      • end
    • What Languages are they?
      • view layout [
      • title “Sample GUI”
      • a: area
      • b: button “Fetch URL”
      • [ r: read http://www.bofh.org.uk
      • a/text: r
      • show a
      • ]
      • button “Close” [unview]
      • ]
      • Rebol
      DDJ Article on Rebol - http://www.ddj.com/184404172
    • What Languages are they?
      • indexing
      • title: &quot;Hello World&quot;;
      • author: &quot;Michael Neumann&quot;;
      • class MAIN creation
      • make
      • feature
      • make is
      • do
      • io.put_string(&quot;Hello World&quot;);
      • io.new_line
      • end -- make
      • end -- class MAIN
      • Eiffel
    • What Languages are they?
      • module HelloWorld (main) where
      • main = putStr &quot;Hello World &quot;
      • Haskell
    • What Languages are they?
      • 'Hello World' out.
      • Smalltalk
    • What Languages are they?
      • (print &quot;Hello World&quot;)
      • LISP
    • What Languages are they?
      • ?- write('Hello World'), nl.
      • Prolog
    • What Languages are they?
      • <%@ language=&quot;javascript&quot; %>
      • <html><body>
      • <%
      • Response.Write('Hello World!');
      • %>
      • </body></html>
      • JavaScript
    • What Languages are they?
      • using System;
      • class HelloWorld {
      • static void Main() {
      • Console.WriteLine(&quot;Hello World&quot;);
      • }
      • }
      • C#
    • What Languages are they?
      • puts &quot;Hello World&quot;
      • Tcl, Ruby
    • What Languages are they?
      • documentclass[a4paper]{report}
      • itle{Hello World}
      • egin{document}
      • Hello World
      • end{document}
      • LaTeX