<<Agile DSL Development in Ruby>> 笔记_Ruby_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > Ruby > <<Agile DSL Development in Ruby>> 笔记

<<Agile DSL Development in Ruby>> 笔记

 2011/11/9 8:26:43  Goldice  http://jdoc.iteye.com  我要评论(0)
  • 摘要:pdf见:http://obiefernandez.com/presentations/obie_fernandez-agile_dsl_development_in_ruby.pdf1.WhatisDSL——designedforaspecificdomain——capturesjargoninexecutableform——canbeinternalorexternal2.HowtodesignRubyDSL(1)——Don’ttrytodoanabstractmetamodel?rst
  • 标签:笔记 Ruby

pdf见:http://obiefernandez.com/presentations/obie_fernandez-agile_dsl_development_in_ruby.pdf

?

1. What is DSL

——designed for a specific domain

——captures jargon in executable form

——can be internal or external

?

2. How to design Ruby DSL (1)

——Don’t try to do an abstract metamodel ?rst (不要一开始就尝试建立抽象的元模型,元模型即模型的模型)

——Capture your DSL concepts in valid Ruby?syntax, but don’t worry about implementation(用正确的Ruby语法来标识你的DSL概念,但不需要担心实现)

——Iterate over your Ruby DSL syntax until authors?agree that it faithfully represents the domain,?then work on the implementation(迭代改进你的Ruby DSL语法,直到业务专家认为语法足够真实代表这个领域,然后再考虑实现)

?

3.?

Let the DSL you devise guide your implementation

——Kind of like TDD, don’t do more?than what you need to make your?DSL execute correctly

(让你设计的DSL引导你的实现。某种程度上就像TDD,不要做比你需要的更多的事情来让你的DSL正确运行)

?

DSLs that re?ect business?documents such as contracts are great

——Designing a DSL that’s as close as possible to the document it?re?ects makes veri?cation of the system much easier!

(反应商业文档比如合同的DSL是最理想的。设计一种尽可能与领域文档接近的语言可以让系统的证明更为容易)


4.?How to design Ruby DSL (2) —— Agile DSL Development

——Start with short iterations over the design(一开始,针对设计做短周期的迭代)

——Incorporate end-user feedback, pair with them if?possible(吸取终端用户的反馈,如果可能的话与他们结对)

——Do TDD your context cod(利用TDD来写代码

——Do refactor your context code often, but avoid over-engineering it(经常重构你的代码,但不要过度)

?

5. DSL的一些语法技巧

——Optional parentheses(可选的括号)

——Symbol(符号)

——Block(块)

——Literal arrays and hashes

——Variable-length argument(可变长的参数)

?

6.?“the trick to writing DSL’s in Ruby is really knowing what you can and?can’t do with Ruby’s?metaprogramming features —— Jamis Buck, 37signals

(用Ruby编写DSL的技巧在于真正了解使用Ruby的元编程特征你可以做什么,不可以做什么)

?

7.?Different types of Ruby?DSL designs

(1)?Instantiation——Your DSL is simply methods on an object

(2)?Class Macros——DSL as methods on some ancestor class, and subclasses?can then use those methods to tweak the behavior of?themselves and their subclasses

(3)?Top-Level Methods——Your application de?nes the DSL as top-level methods, and?then invokes load with the path to your DSL script.When?those methods are called in the con?guration ?le, they ?modify some central (typically global) data, which your?application uses to determine how it should execute.

(4)?Sandboxing——Your DSL is de?ned as methods of some object, but that?object is really just a “sandbox”. Interacting with the?object’s methods modify some state in the sandbox, which?is then queried by the application

?

8.?Ruby Features used by?DSL implementors

?

?

? Symbols, less noisy than strings

? Blocks, enabling delayed evaluation of code

? Modules, for cleaner separation of code

? Splats, for handling parameter arrays

? eval, instance_eval, and class_eval

? de?ne_method and alias_method

?

9.?It’s a different way of thinking about?writing code, and as such needs to be?learned by doing, not by reading.?Experimentation is the key!

发表评论
用户名: 匿名