• No results found

Software Development Phases

N/A
N/A
Protected

Academic year: 2021

Share "Software Development Phases"

Copied!
32
0
0

Loading.... (view fulltext now)

Full text

(1)

Software Development Phases

Specification of the task

Design of a solution

Implementation of solution

Analysis of solution

Testing and debugging

Maintenance and evolution of the system

Obsolescence

(2)

Specification

Precise description of problem

May be one of the most difficult phases

(3)

Design

Algorithm – set of instructions for solving problem

Not originally done in programming language

pseudocode

Formal modeling language (UML)

Decompose problem into smaller – more manageable subtasks – map to subprograms

Need to be as independent of each other as possible

Reuse

Modification

All domain information should be located only 1 place in the code

Each subprogram should only do 1 task

Each subprogram should be treated as a black box – specification not implementation – called procedural abstraction

(4)

An important topic: preconditionsAn important topic: preconditions and and postconditions

postconditions..

They are a method of specifying what a function They are a method of specifying what a function accomplishes.

accomplishes.

Preconditions and Postconditions

(5)

Preconditions and Postconditions

Frequently a programmer must communicate Frequently a programmer must communicate

precisely

precisely whatwhat a function accomplishes, without any a function accomplishes, without any indication of

indication of howhow the function does its work. the function does its work.

(6)

Example

You are the head of a You are the head of a programming team and programming team and

you want one of your you want one of your

programmers to write a programmers to write a

function for part of a function for part of a

project.

project.

HERE ARE

THE REQUIREMENTS FOR A FUNCTION THAT I

WANT YOU TO WRITE.

I DON'T CARE WHAT METHOD THE

FUNCTION USES, AS LONG AS THESE

REQUIREMENTS ARE MET.

(7)

What are Preconditions and Postconditions?

One way to specify such requirements is with a One way to specify such requirements is with a pair of statements about the function.

pair of statements about the function.

The preconditionThe precondition statement indicates what must be statement indicates what must be true before the function is called.

true before the function is called.

The postconditionThe postcondition statement indicates what will be statement indicates what will be true when the function finishes its work.

true when the function finishes its work.

(8)

Example

void write_sqrt(double x) // Precondition: x >= 0.

// Postcondition: The square root of x has // been written to the standard output.

...

(9)

Example

void write_sqrt( double x) // Precondition: x >= 0.

// Postcondition: The square root of x has // been written to the standard output.

...

}

The precondition and postcondition appear as comments in your

program.

(10)

Example

void write_sqrt( double x) // Precondition: x >= 0.

// Postcondition: The square root of x has // been written to the standard output.

...

}

In this example, the precondition In this example, the precondition requires that

requires that

x >= 0x >= 0

be true whenever the function is be true whenever the function is called.

called.

(11)

Example

write_sqrt( -10 );

write_sqrt( 0 );

write_sqrt( 5.6 );

Which of these function calls Which of these function calls

meet the precondition ?

meet the precondition ?

(12)

Example

Which of these function calls Which of these function calls

meet the precondition ? meet the precondition ?

write_sqrt( -10 );

write_sqrt( 0 );

write_sqrt( 5.6 );

The second and third calls are fine, since the argument is greater than or equal to zero.

(13)

Example

Which of these function calls Which of these function calls

meet the precondition ? meet the precondition ?

write_sqrt( -10 );

write_sqrt( 0 );

write_sqrt( 5.6 );

But the first call violates the

precondition, since the argument is less than zero.

(14)

Example

void write_sqrt( double x) // Precondition: x >= 0.

// Postcondition: The square root of x has // been written to the standard output.

...

}

The postcondition always indicates The postcondition always indicates what work the function has

what work the function has

accomplished. In this case, when the accomplished. In this case, when the

function returns the square root of function returns the square root of xx

has been written.

has been written.

(15)

Another Example

bool is_vowel( char letter )

// Precondition: letter is an uppercase or

// lowercase letter (in the range 'A' ... 'Z' or 'a' ... 'z') . // Postcondition: The value returned by the

// function is true if Letter is a vowel;

// otherwise the value returned by the function is // false.

...

(16)

Another Example

is_vowel( 'A' );

is_vowel(' Z' );

is_vowel( '?' );

What values will be returned What values will be returned

by these function calls ?

by these function calls ?

(17)

Another Example

is_vowel( 'A' );

is_vowel(' Z' );

is_vowel( '?' );

What values will be returned What values will be returned

by these function calls ?

by these function calls ?

truetrue

false false

Nobody knows, because the Nobody knows, because the

precondition has been violated.

precondition has been violated.

(18)

Another Example

is_vowel( '?' );

What values will be returned What values will be returned

by these function calls ? by these function calls ?

Violating the precondition Violating the precondition

might even crash the computer.

might even crash the computer.

(19)

Always make sure the precondition is valid . . .

The programmer who calls the function is The programmer who calls the function is responsible for

responsible for ensuring that the precondition is ensuring that the precondition is valid

valid when the function is called.when the function is called.

AT THIS POINT, MY PROGRAM CALLS YOUR

FUNCTION, AND I MAKE SURE THAT THE PRECONDITION IS

VALID.

(20)

. . . so the postcondition becomes true at the function’s end.

The programmer who The programmer who

writes the function counts writes the function counts on the precondition being on the precondition being

valid, and

valid, and ensures that ensures that the postcondition

the postcondition becomes true

becomes true at the at the function’s end.

function’s end.

THEN MY FUNCTION WILL EXECUTE, AND WHEN

IT IS DONE, THE

POSTCONDITION WILL BE TRUE.

I GUARANTEE IT.

(21)

A Quiz

Suppose that you call Suppose that you call

a function, and you a function, and you

neglect to make sure neglect to make sure that the precondition that the precondition

is valid.

is valid.

Who is responsible if Who is responsible if

this inadvertently this inadvertently

causes a 40-day flood causes a 40-day flood

or other disaster?

or other disaster?

YouYou

The programmer who The programmer who wrote that torrential wrote that torrential

function function

NoahNoah

(22)

A Quiz

Suppose that you call Suppose that you call

a function, and you a function, and you

neglect to make sure neglect to make sure that the precondition that the precondition

is valid.

is valid.

Who is responsible if Who is responsible if

this inadvertently this inadvertently

causes a 40-day flood causes a 40-day flood

or other disaster?

or other disaster?

YouYou

The programmer who The programmer who calls a function is

calls a function is

responsible for ensuring responsible for ensuring

that the precondition is that the precondition is

valid.

valid.

(23)

On the other hand, careful

programmers also follow these rules:

When you write a function, you should make When you write a function, you should make every effort to detect when a precondition has every effort to detect when a precondition has

been violated.

been violated.

If you detect that a precondition has been If you detect that a precondition has been

violated, then take appropriate action (repair or violated, then take appropriate action (repair or

terminate).

terminate).

(24)

On the other hand, careful

programmers also follow these rules:

When you write a function, you should make When you write a function, you should make every effort to detect when a precondition has every effort to detect when a precondition has

been violated.

been violated.

If you detect that a precondition has been If you detect that a precondition has been

violated, then take appropriate action and halt violated, then take appropriate action and halt

the program...

the program...

...rather than causing...rather than causing a disaster.a disaster.

(25)

Example

void write_sqrt( double x) // Precondition: x >= 0.

// Postcondition: The square root of x has // been written to the standard output.

{

assert(x >= 0);

...

The assert function is useful for The assert function is useful for detecting violations of a

detecting violations of a precondition.

precondition.

(26)

Advantages of Using Preconditions and Postconditions

Succinctly describes the behavior of a Succinctly describes the behavior of a function...

function...

... without cluttering up your thinking with ... without cluttering up your thinking with details of how the function works.

details of how the function works.

At a later point, you may reimplement the At a later point, you may reimplement the function in a new way ...

function in a new way ...

... but programs (which only depend on the ... but programs (which only depend on the

precondition/postcondition) will still work with precondition/postcondition) will still work with

no changes.

no changes.

(27)

Precondition Precondition

The programmer who calls a The programmer who calls a function ensures that the

function ensures that the precondition is valid.

precondition is valid.

The programmer who writes a The programmer who writes a function can bank on the

function can bank on the

precondition being true when precondition being true when the function begins execution.

the function begins execution.

Postcondition Postcondition

The programmer The programmer who writes a

who writes a

function ensures function ensures

that the that the

postcondition is postcondition is

true when the true when the

function finishes function finishes

executing.

executing.

Summary

(28)

Standard Library & Standard Namespace

#include directive

Similar to import directive in other languages

Much more primitive

Namespaces – allows limiting visibility of “names”

Standard namespace – standard C++ libraries

2 choices

using namespace std:

Fully qualified identfier

(29)

Exception Handling

Similar to Java and C#

(30)

Running Time Analysis

Machine independent method of measuring run time efficiency

Determine basic operation for the algorithm

Expression the number of operations as a function of the data size

Interested in the order of magnitude of this function – expressed using Big-O notation

(31)

Running Time Analysis

Worst case – maximum number of operations

Best case – minimum number of operations

Average case – depends upon the underlying probability distribution

(32)

Testing and Debugging

Good test data

Correct output known

Include values most likely to causes errors

Boundary values

Fully exercise code

Every line of code is executed by at least 1 test case

References

Related documents

However as previously discussed, the revenue splits from tax sharing are fixed in the vast majority of cases and in fact without fixed shares, the primary advantage of tax sharing

State Level Governance of Health Information Exchange © Image Research 2014.. Using the EHR as a

Electronic Total Station Instruments Global Positioning System (GPS) Digital Photogrammetric Systems Land and Geographic Information system (LIS/GIS)... • Measures horizontal

For example, if the upper end of the voltage window were 260 VDC on equalize and the recommended equalization voltage per cell shown in the battery data sheet was 2.4 V/C, the

Berdasarkan pembobotan di atas diketahui bahwa sebesar 40,71% merupakan Tingkat Kerentanan Tinggi, 44,79% memiliki Tingkat Kerentanan Sedang, sebesar 14,50% memiliki

With all four financing mechanisms, price control results in a price decrease in both the monopolistic and the competitive region due to the incumbent ’s strong market power.. There

CDBG will use the parallel TSEP ranking criterion general scoring definitions to rank the project concept and technical design for the proposed CDBG project.. CDBG will use