程式規格 | -> | 設計 | -> | 分析 |
程式規格與設計
<a> The step <iii> is most meant to "write a program" but
a simple translation process.
<b> To write a program is similat to build a building.
One needs to specify precisely what the program is suppose to do.
Vague idea | -> | precise description |
A precise set of instructions that leads to a solution.
虛擬碼:
A mixture of oral languate and a programming language
to describe a algorithm.
Algorithms are instructions for doing something.
data are the information manipulated by algorithm.
<2> 分解問題
(1) 萃取程序中必要的部份(procedure abstraction)
Abstracting away or hiding from the irrelevant details.
eg. To watch the TV, one doesn't need to know TV works.
(2) 文件
詳細的闡明一個特定函式的作用,但不須解釋它如何運作。
函式的說明文件應該包含:
<i> Precondition for input of function a statement
giving condition that is support to be true when a function is celled.
<i> Postcondition for output of function
A statement decribing what will be true when a function call is completed.
eg.
int days (int year) // Precondition: the parameter year is between // 1800-2001. // Postcondition: the return value is the total days // of the year.
:
<a> When to write the precondition and postcondition,
specify the precondition and postcondition when writing the function's prototype.
<b> Precondition and Postcondition are the interface specification of functions.
They are even more important when a group of programmer work together.
eg. They are the precondition/postcondition contract agreed by all programmers.
(3) Pitfall: failing to ensure the precondition. Wheneven it is possible, always check if the precondition is meet; even sometimes it is impossible.
(4) Assert function, in <assert.h>
assert( ( i > 5) && ( i < 10 ) );=> if it is true no action is taken.
(5) 文件撰寫標準:
A description of how each part of the documentation should be written.
整個軟體系統的發展與維護週期可以看成如下的循環:
<a> The typical cost of maintenance >>
the cost of producing the original system.
<b> The majority of systems programmer's time
is spent on the maintenance of exising system,
not designing completely new systems.