KEMBAR78
S D D Program Development Tools | PPT
Implementation Program Development Techniques
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.
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.
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.
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?
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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”)
Activity 2 The desk check for  Linear(Animals(), “Frog”)  call is reproduced below: 5 4 True Frog 0 4 0 Frog True Search (Count) Count Upper Lower FindItem Linear
Activity 2 Now perform the desk check for  Linear(Animals(), “Cat”)  call is reproduced below: Search (Count) Count Upper Lower FindItem Linear
Activity 2 Now perform the desk check for  Linear(Animals(), “Cat”)  call is reproduced below: 5 4 True Cat 2 Dog 1 Frog 0 4 0 Cat True Search (Count) Count Upper Lower FindItem Linear
Activity 3 There are actually 2 errors in this program, what are they? The function always returns TRUE regardless of the existence of the search item. Should be set to false. The identifier used as the second parameter is called Finditem yet within the code it is SearchItem.
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?
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.
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
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.
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.
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.
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.
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.

S D D Program Development Tools

  • 1.
  • 2.
    Program Development AIMHighlight 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.
  • 3.
    The Structured ApproachAs 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.
  • 4.
    Structured Approach Thestructured 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.
  • 5.
    Modular Structure Theuse 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?
  • 6.
    One Logical TaskWhat 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.
  • 7.
    One Logical TaskExample 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.
  • 8.
    Appropriate Documentation Cleardocumentation 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.
  • 9.
    Errors There arethree 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.
  • 10.
    Syntax Syntax errorsare 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.
  • 11.
    Logic Errors Areerrors 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.
  • 12.
    Run-Time Errors Causedthrough 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.
  • 13.
    Run-Time Errors Errorsin 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.
  • 14.
    Techniques for DetectingErrors 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.
  • 15.
    Techniques for DetectingErrors 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.
  • 16.
    Techniques for DetectingErrors 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.
  • 17.
    Activity 1 Youare 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.
  • 18.
    Some Important PointsIf 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.
  • 19.
    Peer Checking Errorsoften 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.
  • 20.
    Desk Checking Isthe 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.
  • 21.
    Activity 2 Belowis 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
  • 22.
    Activity 2 Belowis 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”)
  • 23.
    Activity 2 Thedesk check for Linear(Animals(), “Frog”) call is reproduced below: 5 4 True Frog 0 4 0 Frog True Search (Count) Count Upper Lower FindItem Linear
  • 24.
    Activity 2 Nowperform the desk check for Linear(Animals(), “Cat”) call is reproduced below: Search (Count) Count Upper Lower FindItem Linear
  • 25.
    Activity 2 Nowperform the desk check for Linear(Animals(), “Cat”) call is reproduced below: 5 4 True Cat 2 Dog 1 Frog 0 4 0 Cat True Search (Count) Count Upper Lower FindItem Linear
  • 26.
    Activity 3 Thereare actually 2 errors in this program, what are they? The function always returns TRUE regardless of the existence of the search item. Should be set to false. The identifier used as the second parameter is called Finditem yet within the code it is SearchItem.
  • 27.
    Activity 4 “Ifevery 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?
  • 28.
    Activity 4 Unexpectedinputs 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.
  • 29.
    Software Tools forDetecting 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
  • 30.
    Breakpoints Are usedto 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.
  • 31.
    Program Traces Tracingin 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.
  • 32.
    Single-Line Stepping Isthe 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.
  • 33.
    Activity 5 “Asubroutine 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.
  • 34.
    Activity 5 Firstset 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.