Download presentation
Presentation is loading. Please wait.
Published byAlicia Jacobs Modified over 9 years ago
1
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques
2
2 Software Design There is a difference between program design and coding. There is a difference between program design and coding. Effective programming requires both. Effective programming requires both. Program design should be a formalised process: Program design should be a formalised process: Describe the problem in terms of the actions that the computer needs to perform. Describe the problem in terms of the actions that the computer needs to perform. Test the description. Test the description. Refine the description to provide more detail. Refine the description to provide more detail. Test the refinements... etc. Test the refinements... etc. Code the program. Code the program. Coding without design should always be avoided. Coding without design should always be avoided.
3
3 Top-Down Design The most widely favoured method of program development. The most widely favoured method of program development. The task is described as a problem. The task is described as a problem. This problem is divided into sub-problems. This problem is divided into sub-problems. Sub-problems are further divided, until the stages are easily represented by program code. Sub-problems are further divided, until the stages are easily represented by program code.
4
4 Program Description Sate the problem in hand. Sate the problem in hand. This statement must be clear and absolutely unambiguous. This statement must be clear and absolutely unambiguous. Clarification of the problem statement frequently requires iteration with the “client”. Clarification of the problem statement frequently requires iteration with the “client”. The problem statement can frequently be broken down into partly or completely autonomous components. The problem statement can frequently be broken down into partly or completely autonomous components. Functional Specification. Functional Specification. For any large programming project this must be a written document that is agreed by all parties (eg “programmers”, “clients” etc). For any large programming project this must be a written document that is agreed by all parties (eg “programmers”, “clients” etc).
5
5 Feasibility The functional specification can be tested for feasibility. The functional specification can be tested for feasibility. There are several possible problem areas: There are several possible problem areas: Completely infeasible problems (ie problems that have no solution - eg division by 0, calculating the square root of negative numbers etc). Completely infeasible problems (ie problems that have no solution - eg division by 0, calculating the square root of negative numbers etc). Practically infeasible problems Practically infeasible problems Infeasible in terms of hardware Infeasible in terms of hardware Infeasible in terms of time Infeasible in terms of time Infeasible in terms of cost Infeasible in terms of cost
6
6 Algorithms An algorithm is the solution for a problem. An algorithm is the solution for a problem. Algorithms must be: Algorithms must be: Finite There must be a measurable point at which the problem can be said to be solved. Finite There must be a measurable point at which the problem can be said to be solved. Ordered The algorithm must consist of a series of steps. Ordered The algorithm must consist of a series of steps. Unambiguous Each step must follow on from a previous step - if choices are made they must be based upon conditions determined earlier in the sequence. Unambiguous Each step must follow on from a previous step - if choices are made they must be based upon conditions determined earlier in the sequence.
7
7 Successive Refinement First - develop an initial solution First - develop an initial solution This does not need to go into much detail This does not need to go into much detail It does not need to be functional program code It does not need to be functional program code It must describe the solution correctly It must describe the solution correctly Secondly - refine this solution Secondly - refine this solution Each stage should be considered as a problem in its own right - a solution developed and described. Each stage should be considered as a problem in its own right - a solution developed and described. The description must again describe the solution correctly The description must again describe the solution correctly Continue until the problem is completely solved Continue until the problem is completely solved “Successive Refinements” “Successive Refinements” Pseudocode Pseudocode
8
8 Pseudocode A detailed description of a program A detailed description of a program Ignore the syntactic rigours of a formal language Ignore the syntactic rigours of a formal language Provide sufficient detail so that each part of the description will have a correspondence with real source code Provide sufficient detail so that each part of the description will have a correspondence with real source code For OO programming, try to design your pseudocode in an OO manner (ie use objects and methods) For OO programming, try to design your pseudocode in an OO manner (ie use objects and methods)
9
9 Example - 1. The Problem Problem Problem “Write a program to find and display the total of nine integers input by the user. The user should be prompted for input, and the integers should be entered in groups of 3 - with the subtotal displayed after the entry of each of these groups” Modified from Meyers, 1992. Example output Example output Enter the first 3 numbers : 3 5 7 Subtotal : 15 Subtotal : 15 Enter the second 3 numbers : 1 3 5 Subtotal : 24 Subtotal : 24 Enter the last 3 numbers : 5 4 1 Total : 34 Total : 34
10
10 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Refinement of third action Refinement of third action
11
11 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Int1 + Int2 + Int3 Sum = Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum Refinement of second action Refinement of second action Refinement of third action Refinement of third action
12
12 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Sum + Int1 + Int2 + Int3 Sum = Sum + Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum Refinement of third action Refinement of third action
13
13 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Refinement of third action Refinement of third action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Sum + Int1 + Int2 + Int3 Sum = Sum + Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum
14
14 Testing a Program Design Desk Tracing Desk Tracing Data values are chosen, and the actions are carried out by hand- tracing the program steps using these values. NB this may be done on paper (with the aid of a calculator). Assertion Testing Assertion Testing Rather than using test data the logic of the algorithm is tested. Rather than using test data the logic of the algorithm is tested. The state of the program is described at any one point, and the effects of a step upon this is considered. This process is then repeated for the entire algorithm. The state of the program is described at any one point, and the effects of a step upon this is considered. This process is then repeated for the entire algorithm.
15
15 Example - Assertion Testing Assertion - when the first three numbers are entered the values of the 1st, 2nd and 3rd numbers are contained in Int1, Int2 and Int3. Assertion - when the first three numbers are entered the values of the 1st, 2nd and 3rd numbers are contained in Int1, Int2 and Int3. Assertion - when Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first group of numbers entered. Assertion - when Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first group of numbers entered. Assertion - when Sum is displayed, the sum of the first group of numbers to be entered is be displayed. Assertion - when Sum is displayed, the sum of the first group of numbers to be entered is be displayed. Assertion - when the second three numbers are entered the values of the 4th 5th and 6th numbers are contained in Int1, Int2 and Int3. Assertion - when the second three numbers are entered the values of the 4th 5th and 6th numbers are contained in Int1, Int2 and Int3. Assertion - when Sum+Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first two groups of numbers entered. Assertion - when Sum+Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first two groups of numbers entered. Etc. Etc.
16
16 Coding and Testing When the design is considered sound, the program is coded. When the design is considered sound, the program is coded. Each line of pseudocode is replaced by real code. Each line of pseudocode is replaced by real code. The code is compiled and syntax errors are fixed. The code is compiled and syntax errors are fixed. The program is run with as many different data sets as possible (including extreme ones). The program is run with as many different data sets as possible (including extreme ones).
17
17 State the problem Is it feasible? Plan and refine an action sequence Does it solve the problem? Write and compile the source code Is it free of syntax errors? Run the program Are the results correct? Run the program Does it do the job? YesYes NoNo YesYes NoNo YesYes NoNo YesYes NoNo YesYes NoNo Hooray!
18
18 Coding Hints Start coding with a template that you know works! Start coding with a template that you know works! Make very small additions/changes and test the partly finished code: Make very small additions/changes and test the partly finished code: Syntax errors - ie does it compile Syntax errors - ie does it compile Functionality - ie does it run correctly Functionality - ie does it run correctly Fix errors as they occur Fix errors as they occur Don’t write a complete program, and then expect it to work first time - it won’t!! Don’t write a complete program, and then expect it to work first time - it won’t!! Use a good coding style Use a good coding style
19
19 Coding Style Write code that is easy to understand Write code that is easy to understand Identifiers should be meaningful Identifiers should be meaningful eg LineCounter rather than n eg LineCounter rather than n The presentation of the code should reflect its structure The presentation of the code should reflect its structure eg indent code blocks, space lines etc. eg indent code blocks, space lines etc. Actions in the code should be commented Actions in the code should be commented Comments should add meaning, not repeat information already in the code Comments should add meaning, not repeat information already in the code eg n++; // increment n - This adds nothing n++; // count lines - This is a useful comment eg n++; // increment n - This adds nothing n++; // count lines - This is a useful comment
20
20 Bad Style public static String mc(int a, char b) {String c=""; while (a>0) { c=c+b; a--;} return (c);}
21
21 Good Style /** * multiChar - method to return a string containing any * one character repeated any number of times. */ public static String multiChar(int number, char character) // number - no. characters to be drawn // character - the character to be drawn { String str=""; // str will contain the multiple characters while (number>0) // character-writing loop - repeat // for each character to to be drawn { str=str+character; // add a single character to str number--; // reduce the number still to be // written by one } // end of character writing loop return (str); // return the multiple characters }
22
22 Java Naming Conventions The main method of an application should be in a class that is contained in a source file of the same name. The main method of an application should be in a class that is contained in a source file of the same name. Eg class myprog in myprog.java (which will compile to myprog.class. Class identifiers should begin with an upper case letter Class identifiers should begin with an upper case letter eg Myclass, String, System etc. eg Myclass, String, System etc. Variable, and method identifiers should begin with a lower case letter (although a mixture of cases may make them more readable. Variable, and method identifiers should begin with a lower case letter (although a mixture of cases may make them more readable. Eg data1, myData, myObject, myMethod(), println() etc. Eg data1, myData, myObject, myMethod(), println() etc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.