s d d program development tools
DESCRIPTION
TRANSCRIPT
![Page 1: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/1.jpg)
Implementation
Program Development Techniques
![Page 2: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/2.jpg)
Program Development
AIM Highlight a number of techniques and tools
available to the software developer to assist in code generation.
These resources will help to reduce the number of errors in the final product.
First we will look what makes a well developed solution and what are the errors that may occur.
![Page 3: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/3.jpg)
The Structured Approach
As mentioned before the function of the translator is to report any syntax errors.
However, just because a program is syntactically correct it doesn’t mean that it is free of errors.
Following a structured approach to developing programs, particularly complex one’s is a way of improving the level of ‘correctness’ in a program.
![Page 4: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/4.jpg)
Structured Approach
The structured approach promotes the following concepts: Use of a clear modular structure. One logical task per subroutine. Appropriate Documentation.
Error free code is more likely to be produced under these circumstances.
![Page 5: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/5.jpg)
Modular Structure
The use of modularisation is the breaking down of the program into smaller more achievable sub-programs. (Top-down)
Each module is tested independently and is only included into the project once it is error free.
What are two examples of modelling diagrams that show the top-down approach?
![Page 6: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/6.jpg)
One Logical Task
What do we mean? Making sure that each sub-program only has
one task. e.g. Print, Save, Update. If sub-programs are complex then they
become harder to debug. Restricting sub-programs to one task also
enhances the reusability of the code.
![Page 7: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/7.jpg)
One Logical Task
Example In a program that requires THREE processes
to be carried out. Read an array from file Sort the array Print the array
Each process is a logical task and should therefore be created as a sub-program.
![Page 8: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/8.jpg)
Appropriate Documentation
Clear documentation within the code, such as comments, appropriate identifier names and indenting of control structures will help in the understanding of the logic of the code.
Identifier naming is when you give a variable or constant an intrinsic or meaningful name.
![Page 9: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/9.jpg)
Errors
There are three types of errors. Syntax Logic Run-time
Syntax errors are detected by the translator. Run-time and logic errors occur when the
code is executed.
![Page 10: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/10.jpg)
Syntax
Syntax errors are any errors that prevent the translator from converting the source code into machine code.
Examples of syntax errors include: typing mistakes, incorrect punctuation and spelling mistakes.
Most syntax errors are picked up in the process of syntactical analysis within translation.
![Page 11: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/11.jpg)
Logic Errors
Are errors in the design of code that result in incorrect output.
Examples include continuos loops and incorrect calculations.
i.e. Sum = Num1+Num2/2 Logic errors are the most difficult to detect
and can only be identified through desk checking or peer checking.
![Page 12: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/12.jpg)
Run-Time Errors
Caused through the inability of the computer to perform a task.
The error or bug is usually linked to a software or hardware problem.
Possible sources of run-time errors include: Incorrect BIOS settings Incorrect use or settings of hardware drivers Application software.
![Page 13: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/13.jpg)
Run-Time Errors
Errors in the software are due to: Division By Zero errors – This process is not
defined by mathematics so it cannot be completed by a computer. i.e. Finding the average of a list if the list is empty.
Arithmetic Overflow – Occurs when a value is outside ranges (-32768 to 32767) or there are to many calculations for the processor.
Accessing inappropriate memory locations – occur when assign a value to identifier that doesn’t exist.
![Page 14: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/14.jpg)
Techniques for Detecting Errors
1. Stubs A stub is a small routine which is yet to be
coded into the solution. The use of stubs allows high level modules
to be tested. Stubs do not perform any real processing
they only simulate processing will occur. Stubs are used to determine if parameters
are passed and modules are called.
![Page 15: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/15.jpg)
Techniques for Detecting Errors
2. Flags Are used to indicate that a certain condition
has been met. (Boolean) Flags are usually used in the termination of
a loop. However in debugging they are used to
signify that an event has occurred correctly.
![Page 16: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/16.jpg)
Techniques for Detecting Errors
Debugging Output Statements Is a statement inserted as a line of code to
display the value of variables at a particular point in the execution of a program.
This allows the programmer to monitor the contents of variables to determine the precise point at which an error has occurred.
![Page 17: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/17.jpg)
Activity 1
You are writing a function that sorts an array of data. Unfortunately you have a number of problems.
Discuss how the following techniques could be used to isolate the source of errors in your sort function. Stubs Flags Debugging Output Statements.
![Page 18: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/18.jpg)
Some Important Points
If the function includes calls to other modules these modules could be replaced with stubs where values returned can be known.
Temporary flags could be used to identify whether or not particular statements have been executed.
Debugging output statements could be used to show the contents of variables at crucial points during operation.
![Page 19: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/19.jpg)
Peer Checking
Errors often occur that are impossible to correct for the original programmer.
Colleagues are able to see the problem from a fresh point of view.
Many software development companies require each individual module to be peer checked and formally signed off.
![Page 20: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/20.jpg)
Desk Checking
Is the process of working through a module by hand.
Highlights the contents of each variable and the changes that occur when data is inputted.
Often called a structured walkthrough. The process of working through the code
statement by statement helps to make the logic clear.
![Page 21: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/21.jpg)
Activity 2
Below is a function that will perform a linear search of an array in VB.Public Function Linear(Search(), FindItem) As Boolean
Dim Lower, Upper, Count
Linear = True
Lower = LBound(Search)
Upper = UBound(Search)
Count = Lower
WHILE Count < Upper
IF Search(Count) = SearchItem THEN
Linear = True
Count = Upper
END IF
Count = Count + 1
END Function
![Page 22: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/22.jpg)
Activity 2
Below is the array that is to be searched. Animals(0) = “Frog” Animals(1) = “Dog” Animals(2) = “Cat” Animals(3) = “Cow” Animals(4) = “Ant”
To perform a desk check a call routine is entered i.e. Linear(Animals(), “Frog”)
![Page 23: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/23.jpg)
Activity 2 The desk check for Linear(Animals(), “Frog”) call
is reproduced below:
Linear FindItem Lower Upper Count Search
(Count)
True Frog 0 4 0 Frog
True 4
5
![Page 24: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/24.jpg)
Activity 2 Now perform the desk check for Linear(Animals(),
“Cat”) call is reproduced below:
Linear FindItem Lower Upper Count Search
(Count)
![Page 25: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/25.jpg)
Activity 2 Now perform the desk check for Linear(Animals(),
“Cat”) call is reproduced below:
Linear FindItem Lower Upper Count Search
(Count)
True Cat 0 4 0 Frog
1 Dog
2 Cat
True 4
5
![Page 26: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/26.jpg)
Activity 3
There are actually 2 errors in this program, what are they?
1. The function always returns TRUE regardless of the existence of the search item. Should be set to false.
2. The identifier used as the second parameter is called Finditem yet within the code it is SearchItem.
![Page 27: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/27.jpg)
Activity 4
“If every path and every boundary condition have been tested and the output matches exactly the expected output then surely the code must be free of errors.”
This statement is not true why?
![Page 28: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/28.jpg)
Activity 4
Unexpected inputs with different data types or ranges can cause errors.
Mathematical errors such as division by zero. Arithmetic errors can occur when the code is
logically correct. Communication errors in regards to validating
data sent from outside devices.
![Page 29: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/29.jpg)
Software Tools for Detecting Errors in Code
Most software development environments include tools to assist the programmer in the task of isolating errors in source code.
The following three tools are commonly available to assist in the detection of logic and run-time errors. Breakpoints Program Traces Single Line Stepping
![Page 30: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/30.jpg)
Breakpoints
Are used to temporarily halt the execution of the code.
Once the execution has stopped it is possible to view the current value of variables.
By adding breakpoints at strategic points in the code it is possible to locate the source of the error.
![Page 31: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/31.jpg)
Program Traces
Tracing in terms of error detection, refers to tracking the execution of statements and recording the changing contents of variables.
Many software environments produce a trace file. The file maintains a log of all the transactions that have taken place.
![Page 32: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/32.jpg)
Single-Line Stepping
Is the process of halting the execution after each statement is executed.
After each step, the values of variables can be displayed and minor changes made.
This process can become monotonous. However, variations are provided which allow users to step over functions which may be error-free.
![Page 33: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/33.jpg)
Activity 5
“A subroutine is under development that reads a sequential file of records. As each record is read various calculations are made. A logic error exists as some calculations are incorrect.”
Explain how the use of single line stepping could be used to isolate the problem.
![Page 34: S D D Program Development Tools](https://reader033.vdocument.in/reader033/viewer/2022061223/54c43a8c4a7959511c8b456f/html5/thumbnails/34.jpg)
Activity 5
First set up a series of breakpoints to allow the viewing of relevant variables contents.
Start the single line stepping process with the watch window open. Progressively step through the code observing the changes occurring in the window watch.
The records affected by the logic error should now be identifiable.