<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
><channel><title>Himmel &#187; domain specific language</title> <atom:link href="http://lazing.ave7.net/tag/domain-specific-language/feed/" rel="self" type="application/rss+xml" /><link>http://lazing.ave7.net</link> <description>时间很长；现在很短；距离很长；相遇很短</description> <lastBuildDate>Wed, 11 Jan 2012 18:03:14 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> <item><title>笔记：DSL之二 使用DSL</title><link>http://lazing.ave7.net/2009/notes-dsl-bis-use-dsl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=notes-dsl-bis-use-dsl</link> <comments>http://lazing.ave7.net/2009/notes-dsl-bis-use-dsl/#comments</comments> <pubDate>Tue, 23 Jun 2009 12:25:29 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Code Talk]]></category> <category><![CDATA[domain specific language]]></category> <category><![CDATA[dsl]]></category><guid isPermaLink="false">http://lazing.ave7.net/2009/%e7%ac%94%e8%ae%b0%ef%bc%9adsl%e4%b9%8b%e4%ba%8c-%e4%bd%bf%e7%94%a8dsl/</guid> <description><![CDATA[这篇笔记的内容来自MF http://martinfowler.com/dslwip/UsingDsls.html&#160; 领域特殊语言(Domain Specific Language)定义 a computer programming language of limited expressiveness focused on a particular domain. 关注特定领域表述有限的计算机程序语言 四个重要元素 computer programming language:A DSL is used to humans to instruct a computer to do something, as well as helping communication between humans. 计算机语言 DSL帮助用户与计算机交互，同时辅助人与人的交流。 language nature: A DSL is a programming language, and as such should <a href="http://lazing.ave7.net/2009/notes-dsl-bis-use-dsl/"> read more <span class="meta-nav">&#187;</span></a><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[</p><blockquote><p>这篇笔记的内容来自MF <a href="http://martinfowler.com/dslwip/UsingDsls.html">http://martinfowler.com/dslwip/UsingDsls.html</a>&#160;</p></blockquote><h3>领域特殊语言(Domain Specific Language)定义</h3><blockquote><p>a computer programming language of limited expressiveness focused on a particular domain.</p></blockquote><blockquote><p>关注特定领域表述有限的计算机程序语言</p></blockquote><p>四个重要元素</p><ul><li><b>computer programming language:</b>A DSL is used to humans to instruct a computer to do something, as well as helping communication between humans. <br />计算机语言 DSL帮助用户与计算机交互，同时辅助人与人的交流。</li><li><b>language nature:</b> A DSL is a programming language, and as such should have a sense of fluency where the expressiveness comes not just from individual expressions but also the way they can by composed together. <br />语言属性 DSL是一个程序语言，拥有流畅的表述形式，且能够组合完成逻辑。</li><li><b>limited expressiveness:</b> a general purpose programming language provides lots of capabilities, supporting varied data, control, and abstraction structures. All of this is useful but makes it harder to learn and use. A DSL supports a bare minimum of features needed to support its domain. You can&#8217;t build an entire software system in a DSL, rather you use a DSL for one particular aspect of a system. <br />有限的表述 与通用语言相比，DSL应当只对针对的领域做有限的支持，因此，不应当用DSL实现一个完整的应用。</li><li><b>domain focus:</b> a limited language is only useful if it has a clear focus on a limited domain. The domain focus is what makes a limited language worthwhile. <br />领域关注 当明确针对一个特定领域时，有限语言显得非常有用。</li></ul><h4>DSLs的边界</h4><p>DSLs的边界很难明确定义，有些语言和工具，在针对特殊问题是表现了DSL的某种特性，但是他们并不能算做DSLs</p><blockquote><p>If a uses a DSL for its purpose then it stays a DSL, but if someone uses a DSL in a general purpose manner, then it&#8217;s no longer a DSL (in this usage).</p></blockquote><p>这种模糊并不关键，只要工具有用就行了，使用DSL的观点设计和使用软件，是否能够给软件工程带来总体上的优越性是我们主要关注的课题。</p><h4>DSL片段与独立程序</h4><p>DSL可以是一个独立的程序，构建于整体模型之上；也可以是一段执行片段，比如正则表达式，嵌入程序中的SQL等等。</p><h3>使用DSL的理由</h3><h4>加快开发效率（Improving Development Productivity）</h4><p>DSL产生了更加简洁，有效的代码，更好的遵守DRY原则，同时有限的语言也避免了很多程序错误的产生。</p><h4>促进与领域专家的沟通 （Communication with Domain Experts）</h4><p>这里不是说一个COBOL式的幻想，我们不主张让领域专家来用DSL编写业务规则，程序就能够运行。不过DSL简洁生动的语法，的确更容易被领域专家阅读和接受，从而缩小业务模型与程序模型之间的差距。</p><h4>在执行上下文中改变 Change in Execution Context</h4><p>在执行上下文中改变。从而极大的提高了系统的配置化程度，提升其应用功能价值。</p><h4>可替换的计算模型 Alternative Computational Model</h4><p>基于领域模型之上，可以更加灵活的设计计算模型，从而完成业务沉淀。</p><h3>DSLs存在的问题</h3><ul><li>学习曲线 <br />任何一项技术都是有难度的</li><li>构建花费 <br />构建DSL要求更加精确，但其花费并不是在DSL，而在构建模型本身。</li><li>设计难度 <br />DSL很难设计，因为它就像类库一样，因此，这种难度也不是DSL带来的，应当是问题域本身的难度。</li><li>新的DSL的学习难度 <br />DSL构建出来的语言也是需要学习的，不过这取决于DSL本身的设计。</li><li>DSL版本迁移 <br />API已经有很多重构的工具和方法可以使用，DSL还缺乏这些东西，当然内置式的DSL完全可以用载体语言来实现。</li></ul><h3>DSLs生命周期</h3><p>很多不同的方式：</p><p>Model –&gt; API –&gt; <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a></p><p>DSL –&gt; senarios –&gt; functions</p><p>Frameworks –&gt; controllers –&gt; DSL</p><ul><li><a href="http://lazing.ave7.net/2009/notes-dsl-about-one/" rel="bookmark" title="2009/06/22">笔记：DSL之一 简介</a></li><li><a href="http://lazing.ave7.net/2008/summary-of-the-seven-streets-in-the-development-of-the-progress-of-the-new-080913/" rel="bookmark" title="2008/09/13">新七街开发进度小结 080913</a></li><li><a href="http://lazing.ave7.net/2007/dynamic-language-and-dsl/" rel="bookmark" title="2007/11/29">Dynamic Language and DSL</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2009%2Fnotes-dsl-bis-use-dsl%2F&title=%E7%AC%94%E8%AE%B0%EF%BC%9ADSL%E4%B9%8B%E4%BA%8C+%E4%BD%BF%E7%94%A8DSL" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=499" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2009/notes-dsl-bis-use-dsl/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> <item><title>笔记：DSL之一 简介</title><link>http://lazing.ave7.net/2009/notes-dsl-about-one/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=notes-dsl-about-one</link> <comments>http://lazing.ave7.net/2009/notes-dsl-about-one/#comments</comments> <pubDate>Mon, 22 Jun 2009 13:43:27 +0000</pubDate> <dc:creator>某L</dc:creator> <category><![CDATA[Code Talk]]></category> <category><![CDATA[domain specific language]]></category> <category><![CDATA[dsl]]></category><guid isPermaLink="false">http://lazing.ave7.net/2009/%e7%ac%94%e8%ae%b0%ef%bc%9adsl%e4%b9%8b%e4%b8%80-%e7%ae%80%e4%bb%8b/</guid> <description><![CDATA[打算从今天开始，系统的学习一下DSL相关技术。 这个系列的所有文档都来自于MF的BLIKI中的Domain Specific Languages，其余文字都是对其的理解和整理。 关于什么是DSL，之前的文章有提到过。 简单的说 DSL与通用语言相区别，是为特定目的而生的语言，它并不是什么新东西，历史几乎和计算机的历史一样长。 DSL的应用广泛而常见，比如CSS，比如Wiki。DSL通过分析特定问题域提炼动态模型，从而标准化问题处理流程。 恩，先从MM图看起： 重点概念 DSL的类型 DSL可以分为内部DSL(Internal DSLs)和外部DSL(Internal DSLs)，主要区别在于其与实现语言的关系。 内部DSL的语法是其实现语言的子集，典型的如Ruby；外部DSL通常是定制的特殊语法，如HQL。 Language Workbenches 也是DSL实现的方式之一，特定的平台有其特殊性。 API风格的区别 传统意义的程序语言，在实现具体逻辑的时候，往往是一种命令查询风格API ；而DSL通常是口语化接口。 程序比较，都用Java实现 命令查询风格 Event doorClosed = new Event("doorClosed", "D1CL"); Event drawOpened = new Event("drawOpened", "D2OP"); Event lightOn = new Event("lightOn", "L1ON"); Event doorOpened = new Event("doorOpened", "D1OP"); Event panelClosed = new Event("panelClosed", "PNCL"); Command unlockPanelCmd <a href="http://lazing.ave7.net/2009/notes-dsl-about-one/"> read more <span class="meta-nav">&#187;</span></a><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br />]]></description> <content:encoded><![CDATA[<blockquote><p>打算从今天开始，系统的学习一下<a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a>相关技术。</p><p>这个系列的所有文档都来自于MF的BLIKI中的Domain Specific Languages，其余文字都是对其的理解和整理。</p></blockquote><p>关于什么是DSL，<a href="http://lazing.ave7.net/2007/dynamic-language-and-dsl/">之前的文章</a>有提到过。</p><p>简单的说</p><blockquote><p>DSL与通用语言相区别，是为特定目的而生的语言，它并不是什么新东西，历史几乎和计算机的历史一样长。</p></blockquote><p>DSL的应用广泛而常见，比如CSS，比如Wiki。DSL通过分析特定问题域提炼动态模型，从而标准化问题处理流程。</p><p>恩，先从MM图看起：</p><p><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="image" src="http://lazing.ave7.net/wp-content/uploads/2009/06/image5.png" border="0" alt="image" width="616" height="447" /></p><p>重点概念</p><h3>DSL的类型</h3><p>DSL可以分为内部DSL(<strong>Internal DSLs)</strong>和外部DSL(<strong>Internal DSLs</strong>)，主要区别在于其与实现语言的关系。</p><p>内部DSL的语法是其实现语言的子集，典型的如Ruby；外部DSL通常是定制的特殊语法，如HQL。</p><p>Language Workbenches 也是DSL实现的方式之一，特定的平台有其特殊性。</p><h3>API风格的区别</h3><p>传统意义的程序语言，在实现具体逻辑的时候，往往是一种<strong>命令查询风格API </strong>；而DSL通常是<strong>口语化接口</strong>。</p><p>程序比较，都用Java实现</p><p>命令查询风格</p><pre class="brush:java">    Event doorClosed = new Event("doorClosed", "D1CL");
    Event drawOpened = new Event("drawOpened", "D2OP");
    Event lightOn = new Event("lightOn", "L1ON");
    Event doorOpened = new Event("doorOpened", "D1OP");
    Event panelClosed = new Event("panelClosed", "PNCL");

    Command unlockPanelCmd = new Command("unlockPanel", "PNUL");
    Command lockPanelCmd = new Command("lockPanel", "PNLK");
    Command lockDoorCmd = new Command("lockDoor", "D1LK");
    Command unlockDoorCmd = new Command("unlockDoor", "D1UL");

    State idle = new State("idle");
    State activeState = new State("active");
    State waitingForLightState = new State("waitingForLight");
    State waitingForDrawState = new State("waitingForDraw");
    State unlockedPanelState = new State("unlockedPanel");

    StateMachine machine = new StateMachine(idle);

    idle.addTransition(doorClosed, activeState);
    idle.addAction(unlockDoorCmd);
    idle.addAction(lockPanelCmd);

    activeState.addTransition(drawOpened, waitingForLightState);
    activeState.addTransition(lightOn, waitingForDrawState);

    waitingForLightState.addTransition(lightOn, unlockedPanelState);

    waitingForDrawState.addTransition(drawOpened, unlockedPanelState);

    unlockedPanelState.addAction(unlockPanelCmd);
    unlockedPanelState.addAction(lockDoorCmd);
    unlockedPanelState.addTransition(panelClosed, idle);

    machine.addResetEvents(doorOpened);</pre><p>口语化风格</p><pre class="brush:java">   doorClosed. code("D1CL");
    drawOpened. code("D2OP");
    lightOn.    code("L1ON");
    panelClosed.code("PNCL");

    doorOpened. code("D1OP");

    unlockPanel.code("PNUL");
    lockPanel.  code("PNLK");
    lockDoor.   code("D1LK");
    unlockDoor. code("D1UL");

    idle
        .actions(unlockDoor, lockPanel)
        .transition(doorClosed).to(active)
        ;

    active
        .transition(drawOpened).to(waitingForLight)
        .transition(lightOn).   to(waitingForDraw)
        ;

    waitingForLight
        .transition(lightOn).to(unlockedPanel)
        ;

    waitingForDraw
        .transition(drawOpened).to(unlockedPanel)
        ;

    unlockedPanel
        .actions(unlockPanel, lockDoor)
        .transition(panelClosed).to(idle)
        ;</pre><h3>DSLs实现模型</h3><p>实现DSL，主要是针对特定问题域进行动态状态建模，模型可以是任意的：对象模型，结构化模型或者其他的任何实现模型；程序语言通常会很关注语法以及语义，DSLs中的建模主要就是为了建立问题域的描述语义。</p><h3>DSLs实现方法</h3><p>代码生成(Code-Generation)和解释运行(Interpretation)是DSL的两种实现方式，前者在编译时处理模型，后者在运行时应用模型。</p><p>从实现的角度来讲，前者更加快捷方便，而后者更加精致有效；短期看代码生成可以很快应用，长期看解释运行更能形成效益。<ul><li><a href="http://lazing.ave7.net/2009/notes-dsl-bis-use-dsl/" rel="bookmark" title="2009/06/23">笔记：DSL之二 使用DSL</a></li><li><a href="http://lazing.ave7.net/2007/dynamic-language-and-dsl/" rel="bookmark" title="2007/11/29">Dynamic Language and DSL</a></li><li><a href="http://lazing.ave7.net/2008/summary-of-the-seven-streets-in-the-development-of-the-progress-of-the-new-080913/" rel="bookmark" title="2008/09/13">新七街开发进度小结 080913</a></li></ul><p></p><p><a href="http://www.bshare.cn/share?url=http%3A%2F%2Flazing.ave7.net%2F2009%2Fnotes-dsl-about-one%2F&title=%E7%AC%94%E8%AE%B0%EF%BC%9ADSL%E4%B9%8B%E4%B8%80+%E7%AE%80%E4%BB%8B" title="用bShare分享或收藏本文"><img src="http://static.bshare.cn/frame/images/button_custom1-zh.gif" alt="用bShare分享或收藏本文" /></a></p><br /><div><img src="http://lazing.ave7.net/wp-content/plugins/gd-star-rating/gfx.php?value=0.0" /></div><div>Rating: 0.0/<strong>5</strong> (0 votes cast)</div><br /> <img src="http://lazing.ave7.net/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=496" width="1" height="1" style="display: none;" />]]></content:encoded> <wfw:commentRss>http://lazing.ave7.net/2009/notes-dsl-about-one/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license> </item> </channel> </rss>
