1.2软件构造的质量目标Quality Objectives of Software Construction
上一节搞清楚了“要构造的结果是什么” 这一节要理解清楚“构造的结果如何才算好
课程目标Objective of this lecture
1、 软件构造过程中应考虑的重要质量指标To know quality factors to be cared in software construction
2、如果达不到期望的质量目标,会有什么后果To understand the consequences if quality objectives cannot be achieved
3、有哪些面向质量指标的软件构造技术To know what construction techniques are to be studied for each quality factor in this cours
大纲
1、软件系统的质量特性Quality properties of software systems
A、内部和外部质量目标 *External and internal quality factors*
B、重要的外部质量目标 *Important external quality factors*
C、质量目标之间的折中 *Tradeoff between quality factors*
2、软件的体系结构的五个关键的质量目标Five key quality objectives of software construction
A、易于理解:美观的代码/易懂 *Easy to understand: elegant and beautiful code / understandability*
B、方便改变:可维护性和可适应性 *Ready for change: maintainability and adaptability*
C、廉价开发:可重用性 *Cheap for develop: design for/with reuse: reusabilit y*
D、安全的:健壮性 *Safe from bugs: robustness*
E、运行效率 *Efficient to run: performance*
3、总结 Summary
**阅读材料:**
Object-Oriented Software Construction:第1章
代码大全:第20章
软件工程–实践者的研究方法:第14章
一、软件系统的质量特性Quality properties of software systems
A、内部和外部质量目标 External and internal quality factors
【外部质量因素影响用户,内部质量因素影响软件本身及其开发人员,外部质量是内部质量的结果】
外部质量目标
1、外部质量目标:软件的速度的快慢和是否易于使用之类会被他的使用者发现的质量为外部质量目标External quality factors: qualities such as speed or ease of use, whose presence or absence in a software product may be detected by its users
注:外部质量因素 影响 用户External quality factors affect users
内部质量目标
2、内部质量目标:其他的适用于软件产品的质量类似是否模块化,是否可读为内部质量目标仅能被拥有软件实际文件的开发者看见Other qualities applicable to a software product, such as being modular, or readable, are internal factors, perceptible only to developers who have access to the actual software text.
注:内部质量因素 影响 软件本身和它的开发者Internal quality factors affect the software itself and its developers
结果看重的是外部目标但外部质量取决于内部质量
3、 结果看重的是外部目标In the end, only external factors matter.
4、 但是实现外部目标的关键是内部目标:为了使用者能享受到可见的质量,设计和实现者必须应用内部技术确保那些隐藏起来的质量But the key to achieving these external factors is in the internal ones: for the users to enjoy the visible qualities, the designers and implementers must have applied internal techniques that will ensure the hidden qualities.
注:外部质量取决于内部质量 External quality results from internal quality
B、重要的外部质量目标 Important external quality factors
1、正确性 Correctness
1、正确性:External 1: Correctness
按照预先定义的“规约”执行 Correctness is the ability of software products to perform their exact tasks, as defined by their specification.
正确性:最重要的质量指标Correctness is the prime quality
(注:假设软件系统是按层构造的,每一层保证自己的正确性,同时假设其下层是正确的
Assume a software system is developed in layers. Each layer guarantees its correctness under the assumption that its lower layer is also correct.)
确保正确性的方法:测试和调试:发现不正确、消除不正确 Approaches of ensuring correctness: Testing and debugging Robustness (Chapter 6)
防御式编程:在一开始写程序的时候就确保正确性 Defensive programming such as typing and assertions. Meant to help build software that is correct from the start — rather than debugging it into correctness. 详见Robustness (Chapter 6)
形式化方法:通过形式化验证发现问题 Formal approach: “check”, “guarantee” and “ensure” – Mathematical techniques for formal program specification and verification Formal Language, Graduate courses
2、健壮性Robustness
2、健壮性:External 2: Robustness
A、健壮性是软件系统针对异常情况的处理的能力 Robustness is the ability of software systems to react appropriately to abnormal conditions
**健壮性是对正确性的补充***– Robustness complements correctness.*
**正确性:软件的行为要严格的符合规约中定义的行为***– Correctness addresses the behavior of a system in cases covered by its specification;*
**健壮性:出现规约定义之外的情形的时候,软件要做出恰当的反应***– Robustness characterizes what happens outside of that specification.;*
B、健壮性:出现异常时不要“崩溃( 健壮性是为了确保当某种情况发生后,系统不会导致灾难性的事件发生;它因该产生错误信息,彻底suc的终止它的运行或者使其进入规约约定的模块内);Robustness is to make sure that if h cases do arise, the system does not cause catastrophic events; it should produce appropriate error messages, terminate its execution cleanly, or enter a so-called “graceful degradation” mode.
C、健壮性与异常情况相关,而异常情况通常是通过某种规约确定的。其定义是主观的而非客观的Robustness is concerned with “abnormal case”, which implies that the notions of normal and abnormal case are always relative to a certain specification “normal”和“abnormal”
未被specification覆盖的情况即为“异常情况”– An abnormal case is simply a case that is not covered by the specification
所谓的“异常”,取决于spec的范畴:如果你扩展了specification以前的异常情况就会变成正常情况,甚至你所不希望发生的错误的用户输入的情况都将被忽视,– If you widen the specification, cases that used to be abnormal become normal — even if they correspond to events such as erroneous user input that you would prefer not to happen
“Normal” in this sense does not mean “desirable”, but simply “planned for in the design of the software”. •
Although it may seem paradoxical at first that erroneous input should be called a normal case, any other approach would have to rely on subjective criteria, and so would be useless.
Exception handling (Chapter 6)
3、可扩展性Extendibility
3、可扩展性 External 3: Extendibility
可扩展性:对软件的规约进行修改,是否足够容易Extendibility is the ease of adapting software products to changes of specification.
规模越大,扩展起来越 不容易The problem of extendibility is one of scale
对于小程序来说,更改通常不是一个困难 的问题;但是随着软件越来越大,它变得越来越难以适应。For small programs change is usually not a difficult issue; but as software grows bigger, it becomes harder and harder to adapt.
大型软件系统通常把它的维护者看作是一个巨大的纸牌屋,在这个纸牌屋中,抽出任何一个元素都可能导致整个体系崩溃。– A large software system often looks to its maintainers as a giant house of cards in which pulling out any one element might cause the whole edifice to collapse
为什么要扩展:应对变化 We need extendibility because at the basis of all software lies some human phenomenon and hence fickleness
传统的方法没有充分考虑变化,而是依赖于软件生命周期的理想视图,在该视图中,初始分析阶段冻结需求,流程的其余部分用于设计和构建解决方案– Traditional approaches did not take enough account of change, relying instead on an ideal view of the software lifecycle where an initial analysis stage freezes the requirements, the rest of the process being devoted to designing and building a solution.
提高延展性的两个必要的原则Two principles are essential for improving extendibility
1、 简约主义设计:一个简单的架构比复杂的架构更容易适应变化 Design simplicity: a simple architecture will always be easier to adapt to changes than a complex one
2、分离主义设计:模块越自治,一个简单的改变只影响一个模块或少量模块的可能性越大而不是引发整个系统的连锁反应– Decentralization: the more autonomous the modules, the higher the likelihood that a simple change will affect just one module, or a small number of modules, rather than triggering off a chain reaction of changes over the whole system.
详见Chapter 3 (ADT and OOP)和Chapter 4/5 (Modularity and adaptability)
4、可复用性 Reusability
4、可复用性 External 4: Reusability
一次开发,多 次使用:为许多不同应用程序的构造服务的软件元素Reusability is the ability of software elements to serve for the construction of many different applications.
发现共性:对可复用性的需求来自于这样的观察:软件系统经常遵循相似的模式;可以利用这个共性避免改造解决方案之前遇到的问题。The need for reusability comes from the observation that software systems often follow similar patterns; it should be possible to exploit this commonalityand avoid reinventing solutions to problems that have been encountered before.
可重用的软件元素将适用于许多不同的开发A reusable software element will be applicable to many different developments.
Don’t Repeat Yourself (DRY)
Don’t Re-invent the Wheel
详见Chapter 4 (Design for/with reuse)
5、兼容性Compatibility
5、兼容性External 5: Compatibility
不同的软件系统之间相互可容易的集成Compatibility is the ease of combining software elements with others.
兼容性很重要,因为我们开发软件并不是”在真空中:他们需要彼此反应。Compatibility is important because we do not develop software elements in a vacuum : they need to interact with each other.
但他们经常难以互动,因为他们对世界其他地方做出了不连贯的假设But they too often have trouble interacting because they make conflicting assumptions about the rest of the world.
例如文件格式的兼容性:操作系统支持的各种不兼容的文件格式An example is the wide variety of incompatible file formats supported by many operating systems. A program can directly use another’s result as input only if the file formats are compatible.
兼容性的关键在于保持设计的同构性和同意程序间的通讯标准The key to compatibility lies in homogeneity of design and in agreeing on standardized conventions for inter-program communication.
(兼容性的关键是标准化尤其是标准协议The key to compatibility is standardization, especially standard protocols. )
方法包括Approaches include:
标准化的文件格式: 如在Unix系统中,每个文本文件只是字符序列Standardized file formats, as in the Unix system, where every text file is simply a sequence of characters.
标准化的数据结构: 如在Lisp系统中,所有的数据和程序都由二叉树表示(在Lisp中称为列表)。Standardized data structures, as in Lisp systems, where all data, and programs as well, are represented by binary trees (called lists in Lisp)
标准化的用户界面: 如各种版本的Windows、OS/2和MacOS,其中所有工具都依赖于与用户通信的单一范式,基于标准组件,如Windows、icons、等。Standardized user interfaces, as on various versions of Windows, OS/2 and MacOS, where all tools rely on a single paradigm for communication with the user, based on standard components such as windows, icons, etc
通过定义对软件操作的所有重要实体的标准化访问协议,可以获得更通用的解决方法 More general solutions are obtained by defining standardized access protocolsto all important entities manipulated by the software
6、性能 Efficiency
External 6: Efficiency
效率是指软件系统对硬件资源的需求越少越好,比如处理器时间、内存和外部内存占用的空间、通信设备使用的带宽。Efficiencyis the ability of a software system to place as few demands as possible on hardware resources, such as processor time, space occupied in internal and external memories, bandwidth used in communication devices
.
性能毫无意义,除非有 足够的正确性Efficiency does not matter much if the software is not correct (“do not worry how fast it is unless it is also right ”).
对性能的关注 要与 其他质量属性进行折中 The concern for efficiency must be balanced with other goals such as extendibility and reusability;
过度的优化导致软件不再适应变化和复用– Extreme optimizations make the software so specialized as to be unfit for change and reuse.
过早优化是万恶之源
注:抽象和具体的差异关于最优化Abstract concepts for correctness of computation vs. Concrete implementation for performance through optimization
(效率排在正确性之后:效率和可延展性和可复用性纯在一定矛盾,如效率高一般要求多使用具体类而可延展性和可复用性多要求多使用抽象类,通常效率要求排在可延展性和可复用性之后)
7、 可移植性Portability
7、可移植性External 7: Portability
软件可方便的在不同的技术环 境之间移植:可移植性是指将软件产品转移到各种硬件和软件环境的便利性Portabilityis the ease of transferring software products to various hardware and software environments.
硬件、操作系统:可移植性地址变化不仅只是物理硬件更一般的硬件软件的机器,我们真正的程序,包括操作系统,窗口系统如果适用,和其他基本工具。Portability addresses variations not just of the physical hardware but more generally of the hardware-software machine, the one that we really program, which includes the operating system, the window system if applicable, and other fundamental tools.
8、易用性Ease of use
8、易用性External 8: Ease of use
各种背景和资历的人可以学习使用软件产品*Ease of use is the ease with which people of various backgrounds and qualifications can learn to use software products and apply them to solve problems.
-它还包括易于安装、操作和监视。 It also covers the ease of installation, operation and monitoring.
给用户提供详细的指南:如何为新用户提供详细的指导和解释,而不打扰那些只想直接接触的专家用户。How to provide detailed guidance and explanations to novice users, without bothering expert users who just want to get right down to business.
结构简单 Structural simplicity
一个设计 良好的系统,根据一个清晰的、经过深思熟虑的结构构建,将比一个混乱的系统更容易学习和使用。– A well-designed system, built according to a clear, well thought-out structure, will tend to be easier to learn and use than a messy one.
了解用户Know the user
他们的论点是,一个好的设计师必须努力理解系统的目标用户群体
– The argument is that a good designer must make an effort to understand the system’s intended user community
8、功能性Functionality
9、功能性External 9: Functionalit
功能是系统提供的可能性的范围。 Functionality is the extent of possibilities provided by a system
程序设计中一种不适宜的趋 势,即软件开发者增加越来越多的功能,企图跟上竞争,其结果是程 序极为复杂、不灵活、占用过多的磁盘空间 Featurism (often “creeping featurism”)
更容易的问题是一致性的丢失,这可能是由于添加了新特性而导致的,从而影响了它的易用性。众所周知,用户抱怨新版本产品的所有“花哨功能”让它变得极其复杂。The easier problem is the loss of consistency that may result from the addition of new features, affecting its ease of use. Users are indeed known to complain that all the “bells and whistles” of a product’s new version make it horrendously complex.
更重要的问题是避免过于关注特性而忽略其他特性(忽略总体质量)。
– The more difficult problem is to avoid being so focused on features as to forget the other qualities (Ignorance of overall quality).
What Osmond suggests (the color curve) is, aided by the qualityenhancing techniques of OO development, to maintain the quality level constant throughout the project for all aspects but functionality.
首先考虑一小部分关键特征,并考虑所有质量因素。在开发过程中逐渐添加更多功能,并保证与关键功能相同的质量。
你不会在可靠性、可扩展性等方面妥协:除非你对现有的特性满意,否则你不会继续开发新特性 You just do not compromise on reliability, extendibility and the like: you refuse to proceed with new features until you are happy with the features you have
每增加一小点功能,都确保其他质量属性 不受到损失
Start with a small set of key features with all quality factors considered.
Add more features gradually during development process and guarantee the same quality as key features
9、及时性 Timeliness
9、及时性External 10: Timeliness
及时性:软件系统在用户需要时或之前发布。Timeliness (及时性) is the ability of a software system to be released when or before its users want it.
一个伟大的软件产品如果出现得太晚,可能会完全错过它的目标* A great software product that appears too late might miss its target altogether*
10、其他质量目标Other qualitie
可验证性:可验证性是在验证和操作阶段准备验收程序(尤其是测试数据)和检测故障并跟踪错误的程序的简便性。Verifiability is the ease of preparing acceptance procedures, especially test data, and procedures for detecting failures and tracing them to errors during the validation and operation phases
完整性:完整性(完整性)是软件系统的能力来保护他们的各种组件(程序、数据)对未经授权的访问和修改。Integrity is the ability of software systems to protect their various components (programs, data) against unauthorized access and modification.
可修复性:可修复性是能够促进修复的缺陷Repairability is the ability to facilitate the repair of defects
经济性:作为及时性的伴侣,是软件系统能过按照其预算或者小于预算的资金完成的能力。Economy , the companion of timeliness, is the ability of a system to be completed on or below its assigned budget.
C、内部质量目标Internal quality factors
内部质量目标包括
源代码相关因素,如代码行(LOC),循环复杂性等。Source code related factors such as Lines of Code (LOC), Cyclomatic Complexity, etc
与结构有关的因素,如耦合度,内聚度等。Architecture-related factors such as coupling, cohesion, etc
可读性Readability
可理解性
清晰度和复杂度Understandability
大小
内部质量因素通常用作外部质量因素的部分度量。Internal quality factors are usually used as partial measurement of external quality factors.
复杂性是所有内部质量目标的敌人Complexity is the enemy of almost any external quality factors!
D、质量属性之间的权衡Tradeoff between quality properties
如何才能在不引入各种保护的情况下获得完整性,而这些保护将不可避免地妨碍易用性?How can one get integrity without introducing protections of various kinds, which will inevitably hamper ease of use?
经济似乎经常与功能发生冲突。Economy often seems to fight with functionality
及时性的压力可能会诱使我们使用“快速应用程序开发”技术,而这些技术的结果可能没有太多的可扩展性。Timeliness pressures might tempt us to use “Rapid Application Development” techniques whose results may not enjoy much extendibility.
完整性 VS易用性
经济 VS 功能
效率 VS 可移植性
效率VS 可复用性
经济 VS 可复用性
及时性 VS可扩展性
1.开发人员需要做出权衡。Developers need to make tradeoffs
通常情况下,开发人员会隐式地进行这些折衷,而不会花时间来检查相关问题以及各种可用选项; 效率往往是这种沉默决策中的主导因素。Too often, developers make these tradeoffs implicitly, without taking the time to examine the issues involved and the various choices available; efficiency tends to be the dominating factor in such silent decisions.
真正的软件工程方法意味着努力清晰地陈述标准并有意识地做出选择!– A true software engineering approach implies an effort to state the criteria clearly and make the choices consciously.(正确的软件开发过程中,开发者应该将不同质量因素之间如何做出折中的设 计决策和标准明确的写下来)
2. 作为质量因素之间的权衡可能是必要的,其中一个因素从其他因素中脱颖而出:正确性。Necessary as tradeoffs between quality factors may be, one factor stands out from the rest: correctness.
从来没有任何理由为了诸如效率等其他问题而折衷正确性。There is never any justification for compromising correctness for the sake of other concerns such as efficiency.
如果软件没有执行其功能,则其余都是无用的。If the software does not perform its function, the rest is useless
虽然需要折中,但“正确性”绝不能与其他质量因素折中
E、软件构造的关键问题:Key concerns of software construction
软件构造的关键问题:
上述的所有性质都很重要 All the qualities discussed above are important
但是在目前的软件行业,四个是脱颖而出的: *But in the current state of the software industry, four stand out:
*
1-2:正确性和健壮性:可靠性Correctness and robustness: reliability
手段:
- 系统的软件构建方法Systematic approaches to software construction
- 正式规范Formal specification
- 在开发过程中自动检查Automatic checking during development process
- 更好的语言机制Better language mechanism
- 一致性检查工具Consistency checking tools
3-4:可扩展性和可复用性:模块化
F、面向对象编程如何提高质量:How OOP improves quality
正确性:封装,分散。Correctness: encapsulation, decentralization
健壮性:封装,错误处理。
可扩展性:封装,信息隐藏。
可复用性:模块化,组件,模型,模式。
兼容性:标准化模块和接口。Correctness: encapsulation, decentralization
可移植性:信息隐藏,抽象。Robustness: encapsulation, error handling
易用性:GUI组件,框架。Extendibility: encapsulation, information hidin
效率:可重复使用的组件。
及时性:建模,重用。
经济:重用。
功能性:可扩展性。
二、软件构造的五个关键质量目标Five key quality objectives of software construction
可理解性
1.可理解性Understandability(removed)
可复用性
2.可复用性Reusability
可维护性和适应性
3.可维护性和适应性Maintainability and Adaptability
健壮性
4.健壮性Robustness
性能
5.性能Performance(内存removed
三、总结Summary
软件系统的质量特性Quality properties of software systems
外部和内部质量因素
重要的外部质量因素
质量因素之间的权衡
软件建设的五大质量目标
易于理 解:优雅而漂亮的代码/易于理解的
变化:可维护性和适应性
开发成本低:为重用而设计:
可重用性避免bug:健壮性
高效运行:性能
**本课程要学习的技术(按五大质量目标定位分类)**Construction techniques to be studied in this course (classified by the orientation of five key quality objectives)
参考资料:HIT软件构造课程,MIT软件构造课程