Programming Techniques1 POWER OF LOGIC Programming Techniques “CHI BEN COMINCIA E’ A META’...

32
Programming Techniques 1 POWER OF LOGIC Programming Techniques “CHI BEN COMINCIA E’ A META’ DELL’OPERA” Cutajar and Cutajar

Transcript of Programming Techniques1 POWER OF LOGIC Programming Techniques “CHI BEN COMINCIA E’ A META’...

Programming Techniques 1

POWER OF LOGIC

Programming Techniques

“CHI BEN COMINCIA E’ A META’ DELL’OPERA”

Cutajar and Cutajar

Programming Techniques 2

When you write a program you are solving a problem.

To solve the problem you must derive a solution

To derive a solution you must use your powers of logic

When you write a program you are solving a problem.

To solve the problem you must derive a solution

To derive a solution you must use your powers of logic

POWER OF LOGIC

Programming Techniques 3

STEPS IN PROGRAMMING

Objectives (of program from system specification)

Objectives (of program from system specification)

Writing the instructions in a programming language

Writing the instructions in a programming language

Testing and DebuggingTesting and Debugging

Writing up the program documentationWriting up the program documentation

Implementation (putting the program into action)

Implementation (putting the program into action)

Program planning and designProgram planning and design

Programming Techniques 4

OBJECTIVES IN WRITING PROGRAMS

Objectives define what the program must do!

The resultant program should be : (WORKABLE) RELIABLE: must always do what it is supposed

to do. o ROBUST: program does not crash under exceptional

circumstances. (PERFORMANCE) EFFICIENT: must do it fast and efficiently. READABLE: easy to read and understand by others. MAINTAINABLE: Easy to update and debug. PORTABLE: easily transferable to another type of machine. STORAGE SAVING: ideally must occupy as little memory as

possible.

Programming Techniques 5

PROGRAM PLANNING AND DESIGN

Structured Programming is a term embodying methods of writing programs which are clear in their construction, easy to read and maintain, easy to write and test

Structured programming methods

Top Down Modular DesignTop Down Modular Design

Bottom Up Modular DesignBottom Up Modular Design

Stepwise Refinementmethods

Stepwise Refinementmethods

Programming Techniques 6

A module is a self-contained subprogram, which performs independently one specific function (task).

Advantages in using modules Re-usability Easier to read, debug and maintain (update) Natural division of work Remark Modules can be compiled separately Driver program is required to further test modules

MODULARITY

PROCESSINGInput

ONE entry point

Output

ONE exit point

Programming Techniques 7

TOP-DOWN MODULAR APPROACH

Problem is broken down into a number of components (modules). Each component is progressively decomposed into smaller, more

manageable components until each component can be easily understood.

ProblemProblem

Module AModule A

Module A [1]Module A [1] … Module A [n]Module A [n]

Module BModule B

Module B [1]Module B [1] … Module B [n]Module B [n]

Module A1 [1]Module A1 [1] … Module B1 [1]Module B1 [1] …

Programming Techniques 8

Individual manageable modules are initially identified; progressively these are combined to form larger modules until the original problem request is fully carried out.

Method recommendable only in the case of experienced programmers and the existence of a library of previously

developed modules

BOTTOM-UP MODULAR APPROACH

Module 1Module 1 Module 2Module 2 Module i-1Module i-1 Module iModule i

Module AModule A Module BModule B

Original ProblemOriginal Problem

Programming Techniques 9

EXAMPLE: PROCESSING EXAM RESULTS

A teacher wants to process some exam results:

PROCESSPROCESS OutputInput

Candidate’s name

Index number Mark (out 100)

Passmark >= 40

Credit >= 70 A value of –1

terminates input

Percentage of candidates failing, passing, obtaining a credit

Name Index number Message : Fail ,

Pass or Credit Percentage

candidates Fail, Pass or Credit

Programming Techniques 10

HIERARCHICAL INPUT PROCESS OUTPUT(HIPO) CHART (TO TEACHER’S CAUSE)

Top down approach to solving teacher’s exam results problem:

Prepare Examination Results

Input Details Process Details Output Details

Edit Input

Validate input

Determine Mark

Category

Determine Student Counts

Print Individu

al Details

Print Summar

y

Print Error

Listing

Programming Techniques 11

BASIC FORMS OF ALGORITHM

CONSTRUCTION.

An Algorithm consists of a number of steps which, if followed, would result in the underlying task being carried out.

Using structured programming any algorithm can be written using three basic logical constructs or the Jackson’s Structured Programming (JSP) Techniques

Sequence Selection Iteration

Programming Techniques 12

Sequence The execution of one instruction after another.

Selection :(Branching)

Nested selection allows the number of alternative paths to be arbitrary.

SEQUENCE AND SELECTION

Task A Task B Task C

Test ?

Task A

Task B

TRUE

FALSE

Programming Techniques 13

ITERATION: (LOOPING, REPETITION)

The power of iteration: A process of indeterminate duration is described by an algorithm of finite length.

Programming Techniques 14

EXPRESSING ALGORITHMS.

Some ways of expressing instruction flow independently of any programming language:

• Pseudocode • (Program) Flow charts

Programming Techniques 15

PSEUDOCODE

English-like statements very close to high-level language statements.Example 1: Given variables x and y, required to swap their contents

temp xx yy temp

Example 2: Given input number x, required to check whether even or odd. 

If x mod 2 = 0 Then output message ‘even’

Else output message ‘odd’Example 3: Required to display integer numbers from 1 to 10.

i 0while i <= 10 do

i i+1 …

display the value of iendwhile

Programming Techniques 16

FLOWCHARTS

Program flowcharts show a sequence of (algorithmic) steps in pictorial form.

Some BASIC SYMBOLS used in program flowcharting:

Start/End Process Input/output

Decision PredefinedProcess

Connector

Flow in process

Programming Techniques 17

EXAMPLE: FLOWCHART OF EXAM RESULT PROCESS

Y

Start

InputName,index

,Mark

Is Mark = -1?

Is Mark<40?

Is Mark<70?

Total CountT = F+P+C

IncrementCredit count

C=C+1

IncrementPass count

P=P+1

IncrementFail count

F=F+1 End

N

Y

N

N

Y

SAMPLEPROGRAM

FLOWCHART

SAMPLEPROGRAM

FLOWCHART

PrintIndex number

Print “FAIL” Print “PASS”

Print “CREDIT”

Print F/T*100% P/T*100%C/T*100%

Programming Techniques 18

WRITING THE INSTRUCTIONS IN A PROGRAMMING LANGUAGE (CODING)

Most time-consuming stage Requires a lot of effort (hence expensive) Aids to save time and money

using existing library routines, subroutines and subprograms

other programming aids such as o screen painting software, o report generators, o application generators, o RAD (Rapid Application Development) tools.

Programming Techniques 19

TESTING AND DEBUGGING THE PROGRAM

Program Errors : A program may have any or all of four types of errors: Syntax Errors: A statement in the program violates a rule of the

language, Semantic Errors: Violating rules of language, semantic errors are

concerned with the meaning of language statements (semantics).

Logical Errors: The program runs to completion but gives wrong results or performs wrongly in some way.

Runtime Errors:  Program crashes during execution.

The translator detects syntax and semantic errors but the translator does NOT detect Logical and Run-time errors. These require rigorous testing for detection and correction.

Programming Techniques 20

DEBUGGING PROGRAMS

Aids and techniques:

single stepping through the program setting breakpoints displaying contents of specified variables in

memory dumping and examining the contents of a file dumping and examining the entire contents of

memory

Programming Techniques 21

STAGES OF TESTING

May be quite a lengthy and expensive process.

Stages of testing:

Desk–checking /Dry run Unit testing Module testing Subsystem testing System testing User acceptance testing

o (Alpha testing in the case of bespoke software)o (Beta testing in the case of packaged product)

Programming Techniques 22

TYPES OF TESTING

There are two ways of approaching testing :Functional Testing (Black box testing)

Based on typical, extreme and invalid data values that are representative of those covered by the specification.

Logical Testing (White box testing)Based on examining the internal structure of the program and selecting data which gives rise to

the alternative cases of control flow.

Remarks: Functional testing is not adequate by itself. Logical testing by the programmer during program

development is most effective.

Programming Techniques 23

SELECTING TEST CASES

Every statement in the program is executed at least once.

The effectiveness of all sections of code that detect invalid input is tested.

The accuracy of all processing is verified.

The program operates according to its original design specifications.

Programming Techniques 24

TEST DATA CATEGORIES

Normal/valid data – data the program is designed to handle.

Extreme/critical values – valid data at the limits of acceptability.

exceptional/invalid data – attempt to enter invalid data should not crash the program or give wrong results.

Programming Techniques 25

STAGES OF PROGRAM TESTING:

Unit testing: subprograms (components) need to be individually tested to ensure that they conform to specifications.

Module testing: when combined to form a program, modules must be tested to ensure that these (components) do not act in unexpected ways.

System/Subsystem testing: when the whole set of programs must be tested to ensure that they integrate correctly.

User acceptance testing: When the user of the program (possibly the customer) tests the program to see that it is what is required.

Programming Techniques 26

PROGRAM MAINTENANCE

Program maintenance implies modification of the program.

MAINTENANCE may be:Adaptive maintenance due to identified new requirementsCorrective maintenance due to identified errorsPerfective maintenance due to identified improvements to the existing set up.

Aids to maintenance:Modular designUse of structured programming techniquesReadable CodeGood Documentation

Programming Techniques 27

WRITING UP THE PROGRAM DOCUMENTATION

Program Documentation contents:

A description of the problem to be solved.A program abstract that describes the various

tasks which the program performs (the files used, etc).

Operating instructions on how to run the program. A summary of the program controls which are

built into the program. A test plan and data used to test the program for

accuracy. Any changes made during testing should be recorded.

Programming Techniques 28

DOCUMENTATION TYPES AND PRESENTATIONS

Documentation may be presented in different forms:ManualsOnline help

Documentation types:User Manual Operations manualTechnical Manual

(program listing includes inline documentation)

Programming Techniques 29

USER MANUAL

Typical information in a user manual:

Overview of options available Guidance on the sequence of operations to

follow Screen shots showing screen input forms Instructions on how to enter data Sample report layouts Error messages that may be displayed and

what action to take

Programming Techniques 30

OPERATIONS MANUAL

Documentation of procedures necessary to run the system .

Typical information: System setup procedures, including details for each

application of the files required and consumables requirements

Security procedures Recovery procedures in the event of system failure A list of system messages that might appear on the

operator’s console and what action to take

Programming Techniques 31

TECHNICAL MANUAL

Typical information in a technical manual include:

Overall system plan Data organisation and flow Full annotated listing Details of test data and results

Programming Techniques 32

IMPLEMENTATION (PUTTING THE PROGRAM INTO ACTION)

Implementation phase may include a number of activities:acquisition of new hardware and its installation.

oWhen installing new hardware, this may involve extensive re-cabling and changes in office layouts.

Training the users on the new systemConversion of master files to the new system, or

creation of new master files.