Construction Techniques For Domain Specific Languages

1,912 views

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,912
On SlideShare
0
From Embeds
0
Number of Embeds
135
Actions
Shares
0
Downloads
74
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Construction Techniques For Domain Specific Languages

  1. 1. Construction Techniques for Domain-Specific Languages Brian Guthrie bguthrie@thoughtworks.com http://twitter.com/bguthrie
  2. 2. properties http://www.flickr.com/photos/frozenchipmunk/52753779/
  3. 3. “a computer programming language of limited expressiveness focused on a particular domain.”
  4. 4. “a computer programming language of limited expressiveness focused on a particular domain.”
  5. 5. “a computer programming language of limited expressiveness focused on a particular domain.”
  6. 6. “a computer programming language of limited expressiveness focused on a particular domain.” “iced quad venti (with whip) skinny caramel macchiato”
  7. 7. “a computer programming language of limited expressiveness focused on a particular domain.” “iced quad venti (with whip) skinny caramel macchiato”
  8. 8. “a computer programming language of limited expressiveness focused on a particular domain.”
  9. 9. “a computer programming language of limited expressiveness focused on a particular domain.”
  10. 10. “a computer programming language of limited expressiveness focused on a particular domain.”
  11. 11. “a computer programming language of limited expressiveness focused on a particular domain.”
  12. 12. “a computer programming language of limited expressiveness focused on a particular domain.”
  13. 13. “a computer programming language of limited expressiveness focused on a particular domain.”
  14. 14. “a computer programming language of limited expressiveness focused on a particular domain.”
  15. 15. “a computer programming language of limited expressiveness focused on a particular domain.” <target name="test" depends="compile" description="Runs tests"> <javac destdir="${classes.dir}" debug="true" source="${javac.version}" target="${javac.version}"> <classpath refid="build.classpath"/> <src path="${test.dir}"/> <include name="**/*.java"/> </javac> </target>
  16. 16. “a computer programming language of limited expressiveness focused on a particular domain.” <target name="test" depends="compile" description="Runs tests"> <javac destdir="${classes.dir}" debug="true" source="${javac.version}" target="${javac.version}"> <classpath refid="build.classpath"/> <src path="${test.dir}"/> <include name="**/*.java"/> </javac> </target>
  17. 17. “a computer programming language of limited expressiveness focused on a particular domain.” <target name="test" depends="compile" description="Runs tests"> <javac destdir="${classes.dir}" debug="true" source="${javac.version}" target="${javac.version}"> <classpath refid="build.classpath"/> <src path="${test.dir}"/> <include name="**/*.java"/> </javac> </target>
  18. 18. 2 flavors internal external
  19. 19. 2 flavors internal external
  20. 20. 2 flavors internal external
  21. 21. API
  22. 22. expressiveness implementation details
  23. 23. fluent interface
  24. 24. a behavior capable of relaying or maintaining the instruction context for a series of method calls
  25. 25. methods make little sense out of context
  26. 26. [example]
  27. 27. a good candidate source: http://lobobrowser.org/cobra/java-html-parser.jsp
  28. 28. forces CHOICES early and often
  29. 29. be DECLARATIVE
  30. 30. be accepting
  31. 31. every API is a conversation http://www.flickr.com/photos/11739182@N03/1263985679/
  32. 32. with yourself
  33. 33. with your team members
  34. 34. with your business
  35. 35. patterns http://www.flickr.com/photos/mukluk/477913951/
  36. 36. example one method chaining | type transmogrification
  37. 37. example one method chaining | type transmogrification make modifier methods return the host  object so that multiple modifiers can be invoked in a single expression.
  38. 38. example one method chaining | type transmogrification
  39. 39. example one method chaining | type transmogrification transform types as needed as part of a fluent interface call
  40. 40. start with the goal http://www.flickr.com/photos/keylosa/184606430/
  41. 41. Calendar
  42. 42. Mocha
  43. 43. what does expects return?
  44. 44. mocha/mock.rb (ArgumentIterator#each returns the Expectation-trust me)
  45. 45. mocha/expectation.rb
  46. 46. the finishing problem when will it all end?
  47. 47. implied contract type transformations are hidden from the caller the system will arrive at some desired state
  48. 48. example two nested closures | semantic model
  49. 49. example two nested closures | semantic model
  50. 50. example two nested closures | semantic model express statement sub- elements of a function call by putting them  into a closure in an argument
  51. 51. example two nested closures | semantic model
  52. 52. example two nested closures | semantic model the domain model underpinning the DSL
  53. 53. Awsymandias look on my racks, oh ye mighty, and despair. http://github.com/bguthrie/awsymandias http://www.flickr.com/photos/stuckincustoms/197905054/
  54. 54. define an environment
  55. 55. persist metadata to S3
  56. 56. spin up in EC2
  57. 57. DSL is a wrapper for a rich domain model don’t corrupt it!
  58. 58. important definition != domain model
  59. 59. domain model dsl definition
  60. 60. A DSL is a language parse its inputs! keep your domain model clean!
  61. 61. example three literal extension | string polishing
  62. 62. example three literal extension | string polishing add methods to program literals “monkey patching”
  63. 63. example three literal extension | string polishing simple string substitutions to convert nearly code to actual code
  64. 64. the problem
  65. 65. source: http://lobobrowser.org/cobra/java-html-parser.jsp
  66. 66. the goal
  67. 67. web page to object model
  68. 68. org.w3c.Node
  69. 69. org.w3c.Node java.util.List
  70. 70. groovy already extends Node
  71. 71. DOMCategory
  72. 72. (brief digression)
  73. 73. shotgun approach to open classes
  74. 74. “all willy-nilly”
  75. 75. http://www.flickr.com/photos/tenioman/2771903123/
  76. 76. irb
  77. 77. script/console (in rails)
  78. 78. back to Groovy...
  79. 79. use (DOMCategory) { children(), attributes(), Element text(), name(), parent(), depthFirst(), breadthFirst() NodeList size(), list(), text(), child }
  80. 80. this is awesome!
  81. 81. and speaking of which...
  82. 82. we can do better!
  83. 83. search?
  84. 84. example four literal extension | method chaining
  85. 85. literal extension at the object level
  86. 86. jQuery objects act like arrays
  87. 87. jQuery objects are arrays
  88. 88. duck typing? http://www.flickr.com/photos/martinlabar/694274715/
  89. 89. example five method chaining andChaining andChaining
  90. 90. message chains
  91. 91. mimic: cloning is expected and encouraged
  92. 92. “iced quad venti (with whip) skinny caramel macchiato”
  93. 93. calories http://www.flickr.com/photos/lifeontheedge/2077384723/ “the leaning tower of bacon”
  94. 94. http://www.flickr.com/photos/wili/214317898/ bringing it all back home
  95. 95. a DSL is: - an API - a language - a conversation
  96. 96. be DECLARATIVE
  97. 97. know your audience
  98. 98. fluent interface
  99. 99. message chains
  100. 100. nested function | closure
  101. 101. include  use  extend  eval
  102. 102. Brian Guthrie bguthrie@thoughtworks.com http://twitter.com/bguthrie questions?

×