CSDN博客

img silures

极限编程(Extreme Programming)—变化的代价

发表于2004/10/30 13:36:00  804人阅读

分类: 编程思想 极限编程

极限编程(Extreme Programming)—变化的代价

march-bird lucian yjf taopin wl jazz韩伟 nullgate Simon[AKA](转载自cutter.com)    2003年09月15日

  The Cost of Change

  变化的代价


  Early on in Beck's book, he challenges one of the oldest assumptions in software engineering. From the mid-1970s, structured methods and then more comprehensive methodologies were sold based on the "facts" shown in Figure 1. I should know; I developed, taught, sold, and installed several of these methodologies during the 1980s.



Figure 1 -- Historical lifecycle change costs.

Figure 2 -- Comtemporary lifecycle change costs.

  Beck从他的早期的著作开始,就不断向那些软件工程中的一?quot;古训"发出挑战。从19世纪70年代中期的结构化方法,以至后来的那些更复杂的方法,他们都基于如图1所示的那个"事实",在整个80年代,我必须了解、使用、讨论、实施这些方法。
  
  Beck asks us to consider that perhaps the economics of Figure 1, probably valid in the 1970s and 1980s, now look like Figure 2 - that is, the cost of maintenance, or ongoing change, flattens out rather than escalates. Actually, whether Figure 2 shows today's cost profile or not is irrelevant -- we have to make it true! If Figure 1 remains true, then we are doomed because of today's pace of change.
  
  Beck却给我们提了一个问题,那些在70年代和80年代也许还能起到效果的方法,他们的经费开销状况(如图1)现在已经发生了变化(如图2),也就是说,维护的成本(也可以等价为不断发生的变化)降低了,而不是越来越高。实际上,图2所示的开销情况在当今是否是事实其实并不重要,重要的是我们必须认识到,如果图1的现象还在继续重演的话,我们只有死路一条,因为当今时代变化实在太快了(也就是说维护的成本将是一个天价)。

  The vertical axis in Figure 1 usually depicts the cost of finding defects late in the development cycle. However, this assumes that all changes are the results of a mistake -- i.e., a defect. Viewed from this perspective, traditional methods have concentrated on "defect prevention" in early lifecycle stages. But in today's environment, we can't prevent what we don't know about -- changes arise from iteratively gaining knowledge about the application, not from a defective process. So, although our practices need to be geared toward preventing some defects, they must also be geared toward reducing the cost of continuous change. Actually, as Alistair Cockburn points out, the high cost of removing defects shown by Figure 1 provides an economic justification for practices like pair programming.

  图1中的y轴通常用来表示在开发周期的后期发现错误后需要花费的改错成本。可是,这正验证了一个假设,即后期所有需要做的开动均来自前期的一个错误,比方说一个设计缺陷。从这一点来看,传统方法太依赖于在软件生命周期的早期"不出错"。但是在当今瞬息万变的环境中,我们不能完全预防住那些我们预测不到的东西--即由应用需求不断增长而带来的变化,并且这种变化在早期不可能遇见并加以预防。因此,虽然我们要尽可能在早期做出某些应付变化的预防措施,但是更重要的是我们要减少后期改变所带来的开销。正如 Alistai Cockburn 所指出的,需要高成本的图1所示的那种改正缺陷方法,正好从节省开支的角度给了一些实用的方法(如配对编程)一个好的理由。

  In this issue of eAD, I want to restrict the discussion to change at the project or application level -- decisions about operating systems, development language, database, middleware, etc., are constraints outside the control of the development team. (For ideas on "architectural" flexibility, see the June and July 1999 issues of ADS.) Let's simplify even further and assume, for now, that the business and operational requirements are known.

  在本期eAD杂志中,我打算把讨论定位于项目或应用软件层次上的变化--对类似操作系统、编程语言、数据库、组件等的讨论不在讨论之列。(关于软件结构的灵活性,可以参考ADS杂志1999年6月的那期)另外,让我们进一步做个简化,即假定软件的用户需求已经确定。

  Our design goal is to balance the rapid delivery of functionality while we also create a design that can be easily modified. Even within the goal of rapid delivery, there remains another balance: proceed too hurriedly and bugs creep in; try to anticipate every eventuality and time flies. However, let's again simplify our problem and assume we have reached a reasonable balance of design versus code and test time.

  我们的目标是既能快速不断的发布新功能,同时又要让软件的设计易于更改。即使是在快速发布这个目标下,仍然需要?quot;快速发布但Bug丛生"和"面面俱到但旷日持久"之间进行取舍。因此,让我再简化一下我们要讨论的问题,我们假定我们已经在设计、编码和测试这三者之间取得了合理的平衡。

  With all these simplifications, we are left with one question: how much anticipatory design work do we do? Current design produces the functionality we have already specified. Anticipatory design builds in extra facilities with the anticipation that future requirements will be faster to implement. Anticipatory design trades current time for future time, under the assumption that a little time now will save more time later. But under what conditions is that assumption true? Might it not be faster to redesign later, when we know exactly what the changes are, rather than guessing now?

  在上面这些简化的基础上,还留有一个尾巴:我们在设计时对于未知的未来要看多远?现在的设计已经实现了我们现在想到的一些功能。具有预见性的设计可以使未来的需求更快的获得实现,也就是说预见性设计方法在以现在的时间换取未来的时间,如果一点点现在的时间可以换来未来节约大量时间,当然是划算的。但是这种建设怎么才能成为现实呢?也许未来出了问题就整个重新设计一遍也不慢,那又何必现在瞎猜呢?

  This is where refactoring enters the equation. Refactoring, according to author Martin Fowler, is "the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure." XP proponents practice continuous, incremental refactoring as a way to incorporate change. If changes are continuous, then we'll never get an up-front design completed. Furthermore, as changes become more unpredictable -- a great likelihood today -- then much anticipatory design likely will be wasted.

  这就是我们为什么要提出重构的原因。重构,Martin Fowler说过,是不改变软件对外表现但是重整内务的一种改进。XP方法的支持者在变化的环境中实践了连续的、增量式的重构方法。如果变化是不断演化的的,那就不可能存在什么一步到位的设计方法。说白了,如果变化不可预测--正如当今社会的情况--过多的在设计时考虑以后可能的变化,完全是一种浪费。

Figure 3 -- Balancing design and refactoring, pre-internet.

Figure 4 -- Balancing design and refactoring today.

  I think the diagram in Figure 3 depicts the situation prior to the rapid-paced change of the Internet era. Since the rate of change (illustrated by the positioning of the balance point in the figure) was lower, more anticipatory designing versus refactoring may have been reasonable. As Figure 4 shows, however, as the rate of change increases, the viability of anticipatory design loses out to refactoring- - a situation I think defines many systems today.

  我认为图3给出的是互联网时代到来之前的情况。由于变化的速度慢(图中由天平的支点比较靠左来表示),早期的预测多一些是合理的。但是在图4中,由于变化速度变快乐,设计时预测太多是得不偿失的,这种情况正是现在许多系统所面临的。

  In the long run, the only way to test whether a design is flexible involves making changes and measuring how easy they are to implement. One of the biggest problems with the traditional up- front-design-then-maintain strategy has been that software systems exhibit tremendous entropy; they degrade over time as maintainers rush fixes, patches, and enhancements into production. The problem is worse today because of the accelerated pace of change, but current refactoring approaches aren't the first to address the problem. Back in the "dark ages" (circa 1986), Dave Higgins wrote Data Structured Software Maintenance, a book that addressed the high cost of maintenance, due in large part to the cumulative effects of changes to systems over time. Although Higgins advocated a particular program-design approach (the Warnier/Orr Approach), one of his primary themes was to stop the degradation of systems over time by systematically redesigning programs during maintenance activities.

  在一个长期项目中,检验一个设计是否具有很好的灵活性是通过变化需求,同时看看原设计能否很容易的实现新变化的需求。这种传统的"先设计,再维护"策略的最大问题在于软件系统存在非常大的熵(极易变化,没有规律)。一个系统随着时间的推移,维护、改错、打补丁、增强功能等工作会使系统的熵越来越大。现在由于外部环境变化加快,情况正越来越糟。不过,现在的重构技术也不是第一个试图解决这个问题的方法。早在所谓的"黑暗时期"(circa 1986),Dave Higgins 就写过一本名为"Data Structured Software Maintenance"的书,该书指出了由于随着时间的推移变化的累计影响不断增大,维护所需要的开销也将越来说庞大,Higgins 提出了一种新的设计方法(the Warnier/Orr Approach)用于阻止系统的熵增大所带来的负面影响,该方法的思想是在维护过程中有系统的对程序进行重新设计。
  
  Higgins's approach to program maintenance was first to develop a pattern (although the term pattern was not used then) for how the program "should be" designed, then to create a map from the "good" pattern to the "spaghetti" code. Programmers would then use the map to help understand the program and, further, to revise the program over time to look more like the pattern. Using Higgins's approach, program maintenance counteracted the natural tendency of applications to degrade over time. "The objective was not to rewrite the entire application," said Higgins in a recent conversation, "but to rewrite those portions for which enhancements had been requested."

  Higgins 的方法首先为程序改如何设计设定一种模式(虽然那时还没有模式这个提法),然后在细致的代码设计与"好"的模式之间建立一种映射,程序员即根据这种映射关系来理解系统并修改程序,使修改的结果更接近于那个模式。使用 Higgins 这个方法可以通过维护抵消系统谁时间而熵增大的趋势。Higgins 说:"该方法的目标并不是重写整个系统,而只是重写那些根据需要必须增强的部分。"

  Although this older-style "refactoring" was not widely practiced, the ideas are the same as they are today -- the need today is just greater. Two things enable, or drive, increased levels of refactoring: one is better languages and tools, and the other is rapid change.

  虽然这种原始的"重构"技术并没有被广泛的实践检验,其思想与现在的重构还是相通的,只不过现在的需求变化更快、更大。不过有两个东西驱动、提高了现代的重构技术:一是更好的程序设计语言和开发工具;二是更快的变化需求。
  
  Another approach to high change arose in the early days of RAD: the idea of throwaway code. The idea was that things were changing so rapidly that we could just code applications very quickly, then throw them away and start over when the time for change arose. This turned out to be a poor long-term strategy.

  在早期的 RAD(快速原型开发)方法中还有另一种应付变化的办法:代码抛弃思想。这个思想认为环境和需求变化太快,因此我们唯一的办法只能是快速编写新代码,并且也快速的抛弃老代码。我们认为这不是长久之计。

阅读全文
0 0

相关文章推荐

img
取 消
img