Twitter: @pandamonial www.pandamonial.com Objectives DSL/LOP - - PowerPoint PPT Presentation

twitter pandamonial
SMART_READER_LITE
LIVE PREVIEW

Twitter: @pandamonial www.pandamonial.com Objectives DSL/LOP - - PowerPoint PPT Presentation

Amanda Laucher pcprogrammer@gmail.com Twitter: @pandamonial www.pandamonial.com Objectives DSL/LOP Background Internal/External Visual/Textual Examine Tools C# F# Oslo DSL Background What is a DSL? What is


slide-1
SLIDE 1

Amanda Laucher pcprogrammer@gmail.com Twitter: @pandamonial www.pandamonial.com

slide-2
SLIDE 2

Objectives

 DSL/LOP Background

 Internal/External  Visual/Textual

 Examine Tools

 C#  F#  Oslo

slide-3
SLIDE 3

DSL Background

 What is a DSL?  What is LOP?  Why should you care?

slide-4
SLIDE 4

Is there really a communication gap?

slide-5
SLIDE 5

Domain Experts Type…

Add Kresten Krab Thorup to priority contacts Phone: 555-555-5555 Change Don Syme’s address One Microsoft Way Redmond WA 50505

slide-6
SLIDE 6

Developers Type…

Contacts.Add(“Kresten Krab Thorup”, null, Priority, ”555-555-5555”); if (Contacts.Exists(“Don Syme”)) { Contacts.Update(“Don Syme”, “One Microsoft Way”, “Redmond”, “WA”, “50505”); }

slide-7
SLIDE 7

DSL vs GPL

 Limited Expressiveness  Not Turing complete (mostly)  No ability to build abstractions  Limited power  Focused on a specific domain and make us more

productive within that domain

slide-8
SLIDE 8

Textual vs Visual

slide-9
SLIDE 9

Textual vs Visual

 SQL  Javascript  XML  Build Script Languages

slide-10
SLIDE 10

Internal DSLs

 Molding general purpose language to look like what

the domain experts type

 Fluent Interface

 “The more the use of the API has that language-like

flow, the more fluent it is.” - Martin Fowler

slide-11
SLIDE 11

API

private void makeNormal(Customer customer) { Order o1 = new Order(); customer.addOrder(o1); OrderLine line1 = new OrderLine(6, Product.find("TAL"));

  • 1.addLine(line1);

OrderLine line2 = new OrderLine(5, Product.find("HPK"));

  • 1.addLine(line2);

OrderLine line3 = new OrderLine(3, Product.find("LGV"));

  • 1.addLine(line3);

line2.setSkippable(true);

  • 1.setRush(true);

}

slide-12
SLIDE 12

Fluent Interface

private void makeFluent(Customer customer) { customer.newOrder() .with(6, "TAL") .with(5, "HPK").skippable() .with(3, "LGV") .priorityRush(); }

slide-13
SLIDE 13

Use your languages features!

 Reflection  Open Classes/Extension Methods  Dynamic Typing  Type Inference/Duck Typing  Pattern Matching/Active Patterns  HOF/Partial Application  Quotations

slide-14
SLIDE 14

F#

let bakeMuffins temp mix time = mix let bake = bakeMuffins 180<c> let sift (x,y) = y let FruitMuffins fruit = let container = "muffinPan" let dryIngredients = sift (2.5<cups>,"flour") |> mix (1.5<cups>,"sugar") let moistIngredients = mix (250<ml>,"milk") (1.3<cups>, "oil") (2,"eggs") |> mix (1.25<cups>, fruit) mixture = combine dryIngredients moistIngredients |> fillContainer bake mixture 15<min> |> cool 10<min>

slide-15
SLIDE 15

F#

let FruitMuffins fruit = let container = "muffinPan" let dryIngredients = sift (2.5<cups>,"flour") |> mix (1.5<cups>,"sugar") let moistIngredients = mix (250<ml>,"milk") (1.3<cups>, "oil") (2,"eggs") |> mix (1.25<cups>, fruit) mixture = combine dryIngredients moistIngredients |> fillContainer bake mixture 15<min> |> cool 10<min>

slide-16
SLIDE 16

DSL Workbench

 Oslo  Intentional Software

slide-17
SLIDE 17

External Oslo Demo

slide-18
SLIDE 18

Grammar Output  Results

slide-19
SLIDE 19

Things to consider with DSLs

 Involve Domain Experts in development  Life cycle  DSLs evolve independently of other code and of each

  • ther

 DSLs are used in combination with other DSLs

slide-20
SLIDE 20

Other Tools

 ANTLR  Intentional Software  XText

slide-21
SLIDE 21

.NET folks also watch out for...

 Future Oslo  Axum – Maestro

 DSL for concurrency

 F#

 Great for internal DSLs and walking ASTs

 DLR Languages

 Iron – Python/Ruby  Clojure

slide-22
SLIDE 22

Amanda Laucher pcprogrammer@gmail.com Twitter: @pandamonial www.pandamonial.com