面向语言编程:超越面向对象编程的革命性进步?
在巴塞罗那举行的Server Side's Java专题讨论会上,Martin Fowler和Neal Ford做了一场展示面向语言编程的重要报告。Fowler曾撰文将面向语言编程定义为“围绕一组领域特定语言来构建软件的编程风格”。Fowler和Ford又进一步发展了其中的一些想法(可参见Fowler at Jaoo 2006),并提出了“超越面向对象编程的革命性进步”的可能性。
面向对象编程以分层结构和树状的抽象提供了一种有用的建模范式。然而现实并不总是按层次组织的,Neal Ford指出。现实的“盘根错节,彼此联系”是很难用理想化的树状画面来勾勒其模型的。其结果就是现在广泛使用的aspects和XML,它们渐渐地增加了复杂性,并侵蚀了我们实施抽象的原意。为了弥补这个问题,抽象的水平应该再次提升,因此Ford建议用语言取代分层来作为建模机制。
按照Martin Fowler的说法,面向对象的领域建模让我们得以“汇集词汇”,但语法——将词汇组合起来的方法——却是缺失的;DSL补足了语法的方面。因此面向语言编程引导我们“从思考词汇,即对象,走向一种结合了词汇和语法的语言观念。”
对Neal Ford来说,用DSL来作为一种新的抽象机制令他特别感兴趣的是,它能填补上下文的空缺。在缺乏上下文的环境中,你要“从最基本的共识着手并解释所有的细节”。这就是你与API和框架沟通的方式,因为它们没有“任何内建的上下文”。因此代码中总是不断重复一些上下文,以致成了干扰。相反DSL“总是有着隐含的上下文,上下文几乎从不露面,就算露面也是很少很少,通常最多一次”。因此我们不必一再地提供上下文信息,于是代码更具可读性,也更有表现力。
Fowler和Ford都强调了可读性的重要。他们认为DSL的动机经常被误解。目的并不是为了让业务分析师能够自己写代码,而是为了让他们能够阅读和检验代码,从而填补专业开发者和业务人员之间的罅隙。
有些人厌恶使用面向语言编程的风格,因为他们担心维护的问题以及增加的学习负担,特别是在缺乏强大的IDE来处理这些纯文字的DSL的情况下。Fowler最近在一篇文章中反对说“大一点的框架[……]带来的挑战一点都不比学一门语言少”,他再次强调了单一语言编写的项目的复杂性。并且,Neal Ford强调说如果一门DSL很难读,那么它的设计就是很糟糕的,因为“[使用DSL的]目的之一就是为了创造出更容易阅读的代码”。
至于IDE支持,现今至少有三家主要厂商正为面向语言编程提供这一类工具:Charles Simonyi开发的Intentional Software,Microsoft的Software Factories和JetBrains开发的Meta Programming System。这些工具,Martin Fowler称之为语言工作台(Language Workbench),让设计并使用DSL变得更加简单。这些工具提高了面向语言编程的竞争优势,虽然Fowler相信“还要过几年大多数人才会考虑用[语言工作台]来开发实际的项目。”
你怎么看?面向语言编程有机会成为“下一位明星”吗?语言工作台的能力会在多大程度上影响你在项目中采用DSL的决策呢?
Language-oriented programming : an evolutionary step beyond object-oriented programming?
At a TSS' Barcelona event Martin Fowler and Neal Ford did a keynote presentation on language-oriented programming, summarized here. In his earlier article, Fowler defined this concept as “the general style of development which operates about the idea of building software around a set of domain specific languages”. Fowler and Ford further develop some of the ideas presented by Fowler at Jaoo 2006 and question the eventuality of an “evolutionary step beyond object-oriented programming”.
Object oriented programming provides a useful modelling paradigm based on hierarchies and tree shaped abstractions. Reality however is not always hierarchical, highlights Neal Ford. Its “tangled branches and interconnections” are rather difficult to model with idealized tree pictures. And this results in a widespread use of aspects and XML and eventually adds complexity undermining the very purpose of abstraction. To remedy to this issue the abstraction level should be upgraded and to this end Ford suggests using languages rather than hierarchies as a modelling mechanism.
According to Martin Fowler object-oriented domain modelling allows to “build up a vocabulary” but the grammar – ways to combine these vocabularies – is not defined; DSLs add this grammar side. Therefore language-oriented programming inducts “this shift of moving from thinking about vocabulary, which is objects, to the notion of a language that combines vocabulary and grammar.”
For Neal Ford, what makes the use of DSLs as a new abstraction mechanism particularly interesting is its ability to supply context. In a context free environment one should “start at the lowest level possible of understanding and have to explain every single detail”. This is the way one talks to APIs and frameworks because they do not have "any sort of context built into" them. Hence the code is full of repeated context often perceived as noise. DSLs on the contrary “always have an implicit context that shows up either not at all or shows up in a very, very light way and usually at the most one time”. Thus this context doesn’t have to be supplied over and over again, which makes the code more readable and more expressive.
Both Fowler and Ford stress how critical the readability issue is. They insist that the purpose of DSLs is often misunderstood. It is not to make it possible for business analysts to write code but to make it possible for them to read and to review it, in order to bridge the gap separating professional developers and business people.
Some are reluctant to use the language oriented programming style because of possible maintainability issues and increasing learning burden, especially given the lack of rich IDEs for the plain text DSLs. Fowler, who argued in his recent article that “larger frameworks […] present as much of a challenge to learn as a language”, emphasizes again the complexity of projects written in a single language. Moreover, Neal Ford stresses that if a DSL is hard to read then it was very poorly designed because “one of the goals [of using DSLs is] to create more readable code”.
As for IDE support there are today at least three major vendors offering this kind of tooling to support language oriented programming: Intentional Software developed by Charles Simonyi, Microsoft’s Software Factories, Meta Programming System developed by JetBrains. These tools, referred to as Language Workbenches by Martin Fowler, make it easier to design and then to use DSLs. This increases the competitive advantage of the language oriented programming style even though Fowler believes that it “is going to be a few years before most people can think about using [Language Workbenches] for real projects.”
What is your opinion? Does language oriented programming have a chance to become “the next big thing”? And to which extent the availability of language workbenches tools could affect your decision to use DSLs on your projects?
附英文原文网址:http://www.infoq.com/news/2007/09/Language-oriented-programming
分享到:
相关推荐
- **面向对象**:C#完全支持面向对象编程的所有特性,如封装、继承和多态。 - **安全性**:C#内置了安全机制,可以避免许多常见的编程错误,如数组越界等。 - **性能**:C#利用.NET框架中的公共语言运行时(CLR)来...
面向对象编程提供了一种强大的框架,使程序员能够以更接近自然语言和现实世界的方式思考和解决问题。通过封装、继承和多态性等核心概念,OOP促进了代码的重用性、模块化和可维护性,从而提升了软件开发的效率和质量...
这一革命性的平台旨在超越当前的Web站点,将互联网转变为一个可以互换组件的地方。 - .NET的目标是使微软的软件不仅能够在传统的个人电脑上运行,还能适应新兴的Web时代需求,支持多种设备和平台。 - **1.2 .NET与...
- **面向对象**:支持封装、继承和多态等面向对象编程的核心概念。 - **现代化**:支持LINQ、Lambda表达式等现代编程特性。 - **跨平台能力**:通过.NET Core和.NET 5等版本实现了跨平台的能力。 **1.4 小结** - ...
从C语言到面向对象编程,再到Java和J2ME的出现,我们可以清晰地看到编程语言如何随着计算技术的发展而不断进步。Java不仅解决了早期编程语言的一些局限性,而且还通过其跨平台特性和对移动设备的支持,进一步推动了...
#### C语言的革命性影响 C语言的出现彻底改变了编程的面貌,其影响深远,不可小觑。在C语言出现之前,开发者面临诸多挑战:FORTRAN虽适用于科学计算,却不适于系统编程;BASIC易于学习,但功能有限,结构松散;汇编...
- **面向对象**:C#完全支持面向对象编程,包括封装、继承、多态等。 - **安全性**:C#内置的安全特性有助于防止常见编程错误,如数组越界等。 - **性能**:通过CLR,C#可以实现高性能的应用程序。 - **互操作性...
### C#完全手册知识点梳理 #### 第一部分:C#语言概述 ##### 第一章:.NET编程语言C# ...通过阅读本书,读者可以系统地学习C#语言,掌握面向对象编程的思想和技术,为成为一名优秀的C#开发者打下坚实的基础。
- **面向对象**:C#完全支持面向对象编程(OOP),这使得开发者可以更容易地构建复杂的系统。 - **安全性**:C#的类型安全性和内存管理机制使其更安全。 - **效率**:C#的性能接近于C++,同时保留了高级语言的易用...
- **C#的地位**:C#是专门为.NET平台设计的一种现代化的面向对象编程语言,由微软于2000年发布。它是.NET框架的重要组成部分之一,在.NET生态系统中扮演着核心角色。 - **C#的特点**: - 面向对象:C#支持封装、...
- 面向对象编程是现代软件工程的核心,理解和掌握面向对象的设计原理和技术对于开发高质量的软件非常重要。 ##### 第十章:类 - **10.1 类的声明** - **介绍**:类是面向对象编程中的基本单元,用于定义对象的...
- **面向对象**:C#是一种完全支持面向对象编程的语言。 - **简单易学**:C#语法简洁明了,易于学习。 - **安全性**:通过.NET框架的安全模型提供了强大的安全性。 - **性能**:利用.NET框架的性能优势。 - **...