Domain Specific Languages

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Domain Specific Languages - Presentation Transcript

    1. Domain Specific Language Dr. Weerasak Witthawaskul “ Mr. SweetCorn” (weerasak@hotmail.com) Narisa.com’s NJUG Meeting #3 22 July 2007
    2. 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
    3. Graduate Life
    4. 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
    5. What is DSL?
      • “ วันนี้มีประชุมนริสาดอทคอม ”
      • ภาษาไทย
      • “ ทำตัวติสตดีนักถูกแมวีนมายังทำตัวชิวชิวอยู่อีก ...”
      • ภาษาไทยเด็กแนว (domain specific)
    6. 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?
    7. 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
    8. What Languages are they?
      • #include <stdio.h>
      • main() {
      • printf(&quot;Hello World &quot;);
      • }
      • C
    9. 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)
    10. What Languages are they?
      • <?php
      • echo &quot;Hello World &quot;;
      • ?>
      • PHP
    11. 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?
    12. What Languages are they?
      • PROGRAM HelloWorld;
      • BEGIN
      • WRITELN('Hello World');
      • END.
      • PASCAL
    13. What Languages are they?
      • print &quot;Hello World&quot;
      • PRINT “Hello World”
      • Basic, Python, Ruby, Perl
    14. What Languages are they?
      • SELECT 'Hello World'
      • SQL
    15. What Languages are they?
      • BEGIN
      • DBMS_OUTPUT.put_line('Hello World');
      • END;
      • PL/SQL
    16. What Languages are they?
      • Report Hello_World.
      • Write: &quot;Hello World&quot;.
      ABAP
    17. What Languages are they?
      • io:fwrite(&quot;Hello World~n&quot;).
      Erlang
    18. 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
    19. What Languages are they?
      • % Hello World
      • /Courier findfont
      • 28 scalefont
      • setfont
      • 0 0 moveto
      • (Hello World) show
      • showpage
      • Postscript
    20. What Languages are they?
      • /(?ms)&quot;((?>[^\&quot;]+)?(?>\.[^\&quot;]*)*)/
      • Regex – Regular Expression
    21. 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
    22. What Languages are they?
      • >gi|2501594|sp|Q57997|Y577_METJA PROTEIN MJ0577MSVMYKKILYPTDFSETAEIALKHVKAFKTLKAEEVILLHVIDEREIKKRDIFSLLLGVAGLNKSVEEFENELKNKLTEEAKNKMENIKKELEDVGFKVKDIIVVGIPHEEIVKIAEDEGVDIIIMGSHGKTNLKEILLGSVTENVIKKSNKPVLVVKRKNS
      • BLAST query
    23. What Languages are they?
      • aspect VisitAspect {
        • void Point.acceptVisitor(Visitor v) {
          • v.visit(this);
        • }
      • }
      • AspectJ
    24. 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
    25. What Languages are they?
      • <html>
      • <head>
      • <title>Hello World</title>
      • </head>
      • <body>
      • Hello World
      • </body>
      • </html>
      • Of course – HTML!
    26. 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!
    27. DSL Examples Telecom Adhersion Business Natural Language BNL Pattern Matching Regex Object Relational Mapping Hibernate Publishing Postscript Database Manipulation SQL Domain DSL
    28. DSL – Telecom App Framework Adhearsion (open source telecom application framework) + Asterisk (open source telephony platform)
    29. 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
    30. 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?
    31. 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)
    32. Problems with the example
      • Depends on APIs
      • Code does not match the way the domain is described
      • Still difficult to read and verify
    33.  
    34. 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.
    35. 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();
    36. 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”
    37. 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
    38. 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;
    39. 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;);
    40. 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
    41. 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
    42. Metacase’s MetaEdit+ http://www.metacase.com/fs.asp?vasen=vasen.html&paa=cases/dsm_examples.html
    43. Jetbrains Meta Programming System (MPS)
    44. 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
    45. 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
    46. 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)
    47. Q&A Thai’s resources Narisa.com’s Design & Analysis forum ThaiDev.org
    48. Backup slides
    49. 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
    50. 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
    51. 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
    52. What Languages are they?
      • module HelloWorld (main) where
      • main = putStr &quot;Hello World &quot;
      • Haskell
    53. What Languages are they?
      • 'Hello World' out.
      • Smalltalk
    54. What Languages are they?
      • (print &quot;Hello World&quot;)
      • LISP
    55. What Languages are they?
      • ?- write('Hello World'), nl.
      • Prolog
    56. What Languages are they?
      • <%@ language=&quot;javascript&quot; %>
      • <html><body>
      • <%
      • Response.Write('Hello World!');
      • %>
      • </body></html>
      • JavaScript
    57. What Languages are they?
      • using System;
      • class HelloWorld {
      • static void Main() {
      • Console.WriteLine(&quot;Hello World&quot;);
      • }
      • }
      • C#
    58. What Languages are they?
      • puts &quot;Hello World&quot;
      • Tcl, Ruby
    59. What Languages are they?
      • documentclass[a4paper]{report}
      • itle{Hello World}
      • egin{document}
      • Hello World
      • end{document}
      • LaTeX

    + weerasakweerasak, 2 years ago

    custom

    1818 views, 3 favs, 2 embeds more stats

    Domain Specific Languages presentation to NJUG3 on more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1818
      • 1691 on SlideShare
      • 127 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 101
    Most viewed embeds
    • 126 views on http://weerasak.com
    • 1 views on http://209.85.175.132

    more

    All embeds
    • 126 views on http://weerasak.com
    • 1 views on http://209.85.175.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories