`
Goldice
  • 浏览: 106957 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

<<Agile DSL Development in 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 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!

1
2
分享到:
评论

相关推荐

    Agile Web Development With Ruby On Rails第一及第二版

    《Agile Web Development With Ruby On Rails》是两本广受欢迎的书籍,主要涵盖了使用Ruby on Rails框架进行敏捷Web开发的知识。这本书的第1版和第2版分别详细讲解了如何运用敏捷开发方法来构建高效、可扩展且易于...

    Agile Web Development With Ruby On Rails

    通过以上解析可以看出,《Agile Web Development with Ruby on Rails》这本书是一本全面介绍如何使用Ruby on Rails框架进行敏捷Web开发的指南,不仅覆盖了框架的基本用法,还深入探讨了敏捷开发的原则和实践,对于想...

    Agile Web Development with Rails, 2nd Edition

    &lt;br&gt;Agile Web Development with Rails, 2nd Edition&lt;br&gt;&lt;br&gt;有两份PDF文件,大小分别是7.39MB和6.55MB&lt;br&gt;&lt;br&gt;作者: Dave Thomas , David Heinemeier Hansson , Leon Breedt , Mike Clark , James Duncan Davidson ,...

    Agile Development with ICONIX Process: People, Process, and Pragmatism

    &lt;br&gt;Agile Development with ICONIX Process: People, Process, and Pragmatism&lt;br&gt;&lt;br&gt;by Doug Rosenberg , Mark Collins-Cope , Matt Stephens &lt;br&gt;&lt;br&gt;Publisher: Apress; 1 edition (February 22, 2005)&lt;br&gt;&lt;br&gt;...

    User Stories Applied: For Agile Software Development

    &lt;br&gt;User Stories Applied: For Agile Software Development&lt;br&gt;&lt;br&gt;by Mike Cohn &lt;br&gt;&lt;br&gt;Publisher: Addison-Wesley Professional (March 11, 2004) &lt;br&gt;&lt;br&gt;&lt;br&gt;Agile requirements: discovering what your users...

    Agile Web Development With Ruby On Rails EN第一版

    《敏捷Web开发:Ruby on Rails实战》是编程领域的一本经典著作,专注于使用Ruby on Rails框架进行高效、灵活的Web应用开发。此书的第一版经过修补,补充了第二版未涉及的一些关键知识点,例如fastCGI的部署策略,这...

    Agile+Web+Development+with+Rails中文版.pdf

    《Agile Web Development with Rails》是一本经典的Rails开发指南,中文版的出版使得更多的中国开发者能够深入理解并应用敏捷开发方法与Ruby on Rails框架。这本书是Rails开发者的必备参考资料,它详细介绍了如何...

    [Martin] - Agile Software Development_agile_

    敏捷软件开发(Agile Software Development)是一种以人为核心、迭代、逐步交付的软件开发方法论。这种方法强调灵活性、快速响应变化以及高效的团队协作,旨在在不断变化的需求环境中提供高质量的软件产品。 标题中...

    Pro Agile .NET Development with Scrum

    本书名为《*** Development with Scrum》,旨在向读者展示如何在实际的.NET项目中应用敏捷开发和Scrum方法论。作者提供了一个名为“SuperJumper”的2D游戏开发项目作为案例,详细讲述了敏捷和Scrum在项目中的实施...

    Agile Web Development with Rails 4

    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 ...

    Agile Web Development with Rails

    《Agile Web Development with Rails》(敏捷Web开发:Ruby on Rails)这本书,作为Rails开发新手的教材,强调了敏捷开发方法,并以其帮助开发者建立起一个实用的Web应用。从给出的文件信息来看,这本书正在编写过程...

    Bottlenecks in Agile Software Development

    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 Software Development.pdf

    **敏捷软件开发**(Agile Software Development)是一种以人为本、迭代增量的现代软件工程方法论,它强调快速响应变化,通过持续反馈来提高软件项目的灵活性和效率。在《敏捷软件开发》这本书中,作者Alan S. Koch为...

    Agile.Product.Development.epub

    In the last fifteen years, advances in agile software development, lean product development, human-centered design, design thinking, lean startups and product delivery have helped improve individual ...

    Agile software development principles, patterns, and practices

    英文扫描版,在别人的基础上加了目录

Global site tag (gtag.js) - Google Analytics