S D D Program Development Tools

1,449 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,449
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

S D D Program Development Tools

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

×