免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2206 | 回复: 1
打印 上一主题 下一主题

<<Agile DSL Development in Ruby>> 笔记 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-08 17:01 |只看该作者 |倒序浏览
<<Agile DSL Development in Ruby>> 笔记





pdf见:http://obiefernandez.com/present ... lopment_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 first (不要一开始就尝试建立抽象的元模型,元模型即模型的模型)

——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 reflect business documents such as contracts are great

——Designing a DSL that’s as close as possible to the document it reflects makes verification 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 defines the DSL as top-level methods, and then invokes load with the path to your DSL script.When those methods are called in the configuration file, they  modify some central (typically global) data, which your application uses to determine how it should execute.

(4) Sandboxing——Your DSL is defined 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

• define_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!

论坛徽章:
46
15-16赛季CBA联赛之四川
日期:2018-03-27 11:59:132015年亚洲杯之沙特阿拉伯
日期:2015-04-11 17:31:45天蝎座
日期:2015-03-25 16:56:49双鱼座
日期:2015-03-25 16:56:30摩羯座
日期:2015-03-25 16:56:09巳蛇
日期:2015-03-25 16:55:30卯兔
日期:2015-03-25 16:54:29子鼠
日期:2015-03-25 16:53:59申猴
日期:2015-03-25 16:53:29寅虎
日期:2015-03-25 16:52:29羊年新春福章
日期:2015-03-25 16:51:212015亚冠之布里斯班狮吼
日期:2015-07-13 10:44:56
2 [报告]
发表于 2011-11-08 19:06 |只看该作者
这个文档很好的回答了 i_love_ruby 之前关于 DSL 的问题啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP