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 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
其实这种DSL就是方法调用,只不过方法的参数更加灵活,利用了Ruby的一些tricks
(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
这个可以参见我以前写过的关于Programming Ruby中Metaprogramming的章节,Marcos就是指通过这种方式可以将某些简短的名次扩展成更大的东西。
(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.
你直接在脚本里定义方法,这个方法就会被注册到Object类中,因为你调用脚本的是Object类的上下文,所以这些方法在任何调用的脚本中都可用。
(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!
分享到:
相关推荐
web开发敏捷之道的原书Agile Web Development With Ruby On Rails第一及第二版
Agile Web Development With Ruby On Rails
<br/>Agile Software Development Quality Assurance <br/><br/> by Ioannis G. Stamelos , Pagagiotis Sfetsos <br/><br/> Publisher: IGI Global (March 8, 2007) <br/><br/> Agile methods are a collection ...
<br>Agile Web Development with Rails, 2nd Edition<br><br>有两份PDF文件,大小分别是7.39MB和6.55MB<br><br>作者: Dave Thomas , David Heinemeier Hansson , Leon Breedt , Mike Clark , James Duncan Davidson ,...
Agile Web Development With Ruby On Rails 的第一版的修补版本,有些内容第二版未提及,如fastCGI的部署等
<br>Agile Development with ICONIX Process: People, Process, and Pragmatism<br><br>by Doug Rosenberg , Mark Collins-Cope , Matt Stephens <br><br>Publisher: Apress; 1 edition (February 22, 2005)<br><br>...
Agile Web Development with Rails 5 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书...
<br>User Stories Applied: For Agile Software Development<br><br>by Mike Cohn <br><br>Publisher: Addison-Wesley Professional (March 11, 2004) <br><br><br>Agile requirements: discovering what your users...
In turn, agile software development puts the software first because almost any activity undertaken must be to the benefit of the software that will be delivered.<br><br>This book will help you to ...
Agile Software Development
In this book, we share first-handed experiences gained when introducing agile software development in IBM’s WebSphere Portal product development.
Agile Web Development with Rails
光谈理论很虚,这本书教你会如何进行在实际项目中应用Scrum。
Agile Web Development with Rails (PDF)
We still start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features. This edition now gives new Ruby and Rails users more ...
This master thesis identifies main bottlenecks in agile software development exemplified by research industry partner, the international advanced technology company, Ericsson. Theory of Constraints is...
Agile Java Development with Spring, Hibernate and Eclipse<br>这个是代码,书也在我的资源里。
This book describes user stories and demonstrates how they can be used to properly plan, manage, and test software development projects. The book highlights both successful and unsuccessful ...