﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-hk2000c技术专栏-随笔分类-DSL</title><link>http://www.blogjava.net/hk2000c/category/50091.html</link><description>技术源于哲学，哲学来源于生活

关心生活，关注健康，关心他人

</description><language>zh-cn</language><lastBuildDate>Wed, 09 Nov 2011 21:56:23 GMT</lastBuildDate><pubDate>Wed, 09 Nov 2011 21:56:23 GMT</pubDate><ttl>60</ttl><item><title>[转]DSL：单一语言开发的终结者？</title><link>http://www.blogjava.net/hk2000c/archive/2011/11/10/363364.html</link><dc:creator>hk2000c</dc:creator><author>hk2000c</author><pubDate>Wed, 09 Nov 2011 21:56:00 GMT</pubDate><guid>http://www.blogjava.net/hk2000c/archive/2011/11/10/363364.html</guid><wfw:comment>http://www.blogjava.net/hk2000c/comments/363364.html</wfw:comment><comments>http://www.blogjava.net/hk2000c/archive/2011/11/10/363364.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hk2000c/comments/commentRss/363364.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hk2000c/services/trackbacks/363364.html</trackback:ping><description><![CDATA[<div><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">许多年以来，对于软件项目，企业软件开发的主流实践一直都倾向于在单一的通用编程语言上进行标准化，从而使得Java和C#成为今天编程语言的主流选择。随着越来越多的目光开始投向DSL，也许我们的前脚已经踏在了一道新的门槛之上，向前望去，我们会发现在软件项目中采用多种语言已经成为一个标准，但80年代和90年代初出现的问题不会重现。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">Martin Fowler<a target="_blank" href="http://martinfowler.com/bliki/OneLanguage.html" style="color: #0b59b2; ">提出，也许我们正在迈进这样的一个新时期</a>：</p><blockquote style="padding-right: 5px; padding-left: 5px; margin-right: 0px; margin-left: 20px; background-image: url(http://cdn2.infoq.com/styles/cn/i/bg-blockquote.gif); background-color: #ffffff; font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-position: 5px 5px; background-repeat: no-repeat no-repeat; ">[&#8230;&#8230;]在这个时期内，我们将见证多种语言在同一个项目上的应用，人们就像现在选择框架一样，根据功能来选择相应的语言。</blockquote><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">Fowler称：&#8220;像Hibernate、Struts和ADO这样的大型框架，给人们在学习上带来的挑战，绝不亚于学习一门语言，即便你在单一一门宿主语言上使用这些框架编程也是如此。&#8221;此外，在它们的宿主语言中表述需求的难度可能会相当大，并可能引出笨拙难用的配置文件，&#8220;这些配置文件实际上就是使用XML写的外部领域特定语言&#8221;。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">在语言中嵌入DSL，而不是使用类库，可能会是一个更为合适的解决方案。Martin给出了这样的一个分析结论：&#8220;API就好比是在声明一个词汇表，而DSL则为其增加了相应的语法，使得人们能够写出条理清晰的句子。&#8221;因此，使用DSL而不是框架会使代码丰富表现力，为人们带来&#8220;更良好的抽象处理方式&#8221;，并使&#8220;阅读我们写出的代码及对我们意图的展示变得更加容易&#8221;。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; "><a target="_blank" href="http://www.bofh.org.uk/articles/2007/05/19/domain-agnostic-languages" style="color: #0b59b2; ">Piers Cawley称</a>，DSL的主要特性并非其可读性，而是&#8220;它们对去相应领域的高度专注&#8221;使得它们能够更加明确地表义。Cawley为了阐述他的观点举了一个例子，说明DSL不仅仅能让我们&#8220;写出读起来像领域专家说出来的话一样的程序&#8221;，也可以很技术化，用来代表一个使用它们的语法进行操控的框架。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">Neal Ford也相信，<a target="_blank" href="http://memeagora.blogspot.com/2006/12/polyglot-programming.html" style="color: #0b59b2; ">被他称为多语言编程（Polyglot Programming）的势头正在兴起</a>。在软件开发的这个新纪元中，日益明显的主要特征就是嵌入更多的语言，使人们能够&#8220;为所做的菜选择一把恰到好处的刀，并且恰如其分地使用它&#8221;。他举了一个例子，展示在Java编程语言中并行类库的使用难度，并将其与Haskell作比。Haskell是一门函数式语言，&#8220;消除了变量所带来的副作用&#8221;，并使&#8220;编写线程安全的代码&#8221;变得更容易。Ford强调说，Java和.NET平台都存在Haskell语言的实现（Jaskell和Haskell.net）。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">不再使用单一语言进行开发所带来的风险之一可能让80年代末90年代初所出现的问题又再次重现，当时语言就是完全独立的平台，既不能互操作也不能放在一起良好地使用。Martin Fowler指出，现在的情况有这样的一个重要区别：</p><blockquote style="padding-right: 5px; padding-left: 5px; margin-right: 0px; margin-left: 20px; background-image: url(http://cdn2.infoq.com/styles/cn/i/bg-blockquote.gif); background-color: #ffffff; font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-position: 5px 5px; background-repeat: no-repeat no-repeat; ">在80年代末期，人们很难让各个语言之间紧密地互操作。这些年来，人们花了很大精力创建出可以让不同语言紧密共存的环境。脚本语言在传统上与C语言有着很密切的关系。在JVM和CLR平台上也有人为互操作花费了大量精力。另外人们也在类库上投入了很多人力物力，为的是让语言忽视类库的存在。</blockquote><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">最终，要学习并使用多种语言，对于业界乃至开发人员都可能会变成一项重要资产。《Pragmatic Programmers》这本书里面就说到，由于这样做会对人们对编程的思考方式产生影响，因此这样能帮助人们发现解决问题的新途径。</p><p style="font-family: Lucida, 'Lucida Grande', Tahoma, sans-serif; font-size: 13px; line-height: 19px; background-color: #ffffff; ">您是怎样认为的呢？在下去的五年中，我们会开始混合使用语言，并像用类库一样频繁地使用DSL吗？</p></div><img src ="http://www.blogjava.net/hk2000c/aggbug/363364.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hk2000c/" target="_blank">hk2000c</a> 2011-11-10 05:56 <a href="http://www.blogjava.net/hk2000c/archive/2011/11/10/363364.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>