1.1 良好的資料結構和程式設計之三大要素
程式規格-> 設計-> 分析

<fig 1.1>
  1. 程式規格
    To specify what the program is meant to accomplish,without describing the detials.
  2. 設計
    To select/create the specificdata structures and algorithm to meet the specification.
  3. 分析
    To analyze the correctness of data structures and efficiency of algorithm.

程式規格與設計

<1> 基本的程式設計策略
  1. 程式設計策略
    <i> specify the I/O.
    <ii> design the data structures and algorithm.
    <iii> translate the algorithm in to a computer language.
    <iv> test and debug the program.


    <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.

  2. Specification
    Vague idea-> precise description

    <fig 1.2>

  3. 演算法:
    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.
  4. 資料結構:A structured way to organize data.
    * The purpose of OOP is to combine algorithm and data structures into one package.
  5. coding
  6. 測試與除錯

<2> 分解問題

  1. 進一步細分欲解的問題
    Break down the problem into a few subtasks,then decompose each subtasks into smaller subtasks until the subtasks become too trivial to implement in computer language.
    eg.

    <fig 1.3>
  2. 資訊隱藏 (Information hiding)

    (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.
    if it is false useful error message is printed and program stops.

    (5) 文件撰寫標準:
    A description of how each part of the documentation should be written.

  3. 軟體的生命循環週期
    整個軟體系統的發展與維護週期可以看成如下的循環:
    1. Analysis and specification of the task.
    2. Design of the algotithms and data structures.
    3. Implementation(coding)
    4. Testing.
    5. Maintenance and evolution of the system.
    6. Obsolessence.


    <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.