1 / 100

EE 31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

EE 31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING. INTRODUCTION. WHY PROGRAMMING METHODOLOGY? WHAT IS THE PURPOSE OF STUDYING PROGRAMMING METHODOLOGY?. INTRODUCTION. PROGRAMMING IS AN ART? OR SOME SYSTEMATIC WAY FOR PROGRAMMING? What is programming?

enan
Download Presentation

EE 31331 PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EE 31331PROGRAMMING METHODOLOGY AND SOFTWARE ENGINEERING

  2. INTRODUCTION WHY PROGRAMMING METHODOLOGY? WHAT IS THE PURPOSE OF STUDYING PROGRAMMING METHODOLOGY?

  3. INTRODUCTION PROGRAMMING IS AN ART? OR SOME SYSTEMATIC WAY FOR PROGRAMMING? What is programming? Programming is the translation process/ transformation of a concept/ algorithm/ conceptual operation/ human understandable idea into machine realization/operable code. The objective is to have an effective, correct machine operable code to carry out the underlining process (the intended operations). MAJOR CONCERN: EFFICIENCY AND CORRECTNESS

  4. INTRODUCTION Objective of the course is to develop a programming methodology that will enable us to write small and medium-sized programs that are computational effective and correctly implementing the target operations. A methodology is a collection of methods which works together. Here, in programming methodology, we try to teach a careful and systematic approach to programming.

  5. PROGRAMMING APPROACH There are two programming approaches. The length of the boxes is the passage of time. The first approach does not have the planning phase may lead to extensive debugging. Debugging- not only the syntax, the code, but the correctness of the system/operations being implemented.

  6. PROGRAMMING APPROACH Implementation of a FIR filter A general program for any order finite impulse response or fixed order….. Round off errors.. WHAT IT NEEDS - PLANNING and AN EFFECTIVE WAY OF MULTIPLICATION.

  7. PHASE OF A SOFTWARE PROJECT The basic software project development phases are: Specify, Design, Code, Test, Maintain Specify - answer the question “what is the problem to be solved?” The specification must be precise and complete. For example, the FIR problem, what is the allowable round off error (precision), integer or floating point multiplication, the range of input data and coefficients, How big is it allowed to be? Might it be negative? Is it more important to be fast or to be accurate? (depending on application) Specify may be called ‘Analysis Phase’

  8. PHASE OF A SOFTWARE PROJECT Design- answer the question “how should the problem be solved?”. Design includes finding the suitable abstractions, and decomposition of the problem into manageable components. For FIR problem, how to implement the multiplication, fast, accurate? based on the specification from the first phase. How many modules? reading data, coefficient, multiplication, report data….. error handling, checking the validation of input data…..

  9. PHASE OF A SOFTWARE PROJECT Code - the transformation process of the underlying algorithm into machine readable code based on the specification. The basic problem of it is the coding style. It should be simple and easy to maintain. example refer to sq0.c, sq2.c Test - ensure that the program meets the specification. Not the syntax correctness but the correctness of the implementation of the underlying algorithm/operations. It should have a test plan for such task. Maintain - adapt the program to change of requirements or environment

  10. MEANS OF DEVELOPMENT ALGORITHM- It is the underlying process to be implemented as the machine operable instruction (codes). In order to translate/transform the human understandable concepts, the targeted process/operation is represented as algorithm. The means to represent the algorithm should be a language. In fact, before we can develop program, we need a notation in which to express the development.

  11. ALGORITHM ALGORITHM - it is a finite set of instructions which, if followed, accomplish a particular task. It serves as a mean to express the underlying conceptual operations.

  12. ALGORITHM ALGORITHM must satisfy the criteria: • input - there are zero or more quantities which are externally supplied • output - at least one quantity is produced. • definiteness - each step (instruction) must be clear and unambiguous • finiteness - the algorithm will be terminated after a finite number of steps • effectiveness - every step must be sufficiently basic that it can in principle be carried out by a person using only pencil and paper. • proof of correctness - it must be able to provide a mean to validate the correctness of the implementing operations.

  13. MEANS OF DEVELOPMENT Choice: Natural language - too verbose and imprecise except at the analysis phase. Target programming language - this would involve in too much detail and not flexible, without information hiding and abstraction. Need an intermediate language for program development. PDL, program design language, or pseudocode

  14. INTERMEDIATE LANGUAGE • PSEUDOCODE • It resembles the target language in that: • it is a sequence of operations (steps) • steps is precise and unambiguous • it has similar control structure of any high level structured programming languages such as C, Pascal, Perl Pseudo Code C Code x = max of a, b, c x = a; if (b > x) x = b; if (c > x) x = c; Pseudocode has the concept of information hiding and abstraction that allows the programmer concentrating on the problem solving development instead of coding.

  15. PSEUDOCODE • It is a collection of steps with the following operation rules: • A step is a single operation. • A sequence is a list of steps. • The steps in a sequence are performed one after the others. • A sequence is written as a vertical list of steps • Control structures determine the order of execution when this order is not sequential.

  16. PSEUDOCODE Conditional step has the general form if P then A else B The expression P must be evaluated to either true or false: P is the logical expression, a Boolean expression, or a predicate. The letters A and B denotes steps or sequences of steps. P is evaluated; if the result is true, A is executed. Otherwise, B is executed. In all cases, exactly one of A or B is executed. The conditional step is a one-entry, one exit structure in order to maintain the structured programming concept.

  17. PSEUDOCODE Loop Step has the general form while P do A The layout is important that A has to be indented with respect to while. P is the predicate and A is a step or sequence of steps. The while loop is a one-entry, one-exit control structure. If the predicate P is false when the loop is entered the body, A, is not executed at all. The loop will be terminated only when the predicate P is false.

  18. PSEUDOCODE Sequence of Steps has the general form begin S1; S2; S3 end It starts with a begin and terminated by end. There must be a semicolon, “;”, between each pair of steps and there may be a semicolon after the last step of the sequence.

  19. PROGRAM DESIGN LANGUAGE (PDL) Program Design Language is a developed by Caine, Farber and Gordon in 1975 with the motivation to provide a form of language to implement software design in the same way programming languages implement an algorithm.

  20. PROGRAM DESIGN LANGUAGE • A program design language is a programming language that enforces procedural design with structured programming methodology. Characteristics of a procedural design language are: • Use a limited set of logical constructs: • Sequence • Conditional - if then else, select case • Loop - do while, repeat until • It leads to more readable, testable code, and supported by most modern programming languages.

  21. PROGRAM DESIGN LANGUAGE Properties of a procedural design language are: 1. There is one input arc and one output arc. 2. For each node, there is a path from the input arc to that node to the output arc

  22. PROGRAM DESIGN LANGUAGE

  23. PROGRAM DESIGN LANGUAGE

  24. PROGRAM DESIGN LANGUAGE

  25. PDL FEATURES 1. Structuring capability - Features for structuring a design should correspond to the steps of the design technique chosen. (step-wise refinement possible) 2. Implementation hiding - It should be able to hide the details of lower design levels and their implementation. (level of abstraction) This reduces design complexity and promotes the understandability and modifiability of a design 3. Formality - The design language should be formal enough to expose ambiguities, inconsistencies, and other errors. It should be enable some degree of verification. 4. Ease of construction and modification - It must be able to accommodate changes easily. 5. Ease of understanding - It must promote better and more streamlined development.

  26. PDL STRUCTURES PDL consists of two components: the outer syntax and inner syntax The outer syntax: It states in formal statements, like any programming language but albeit in a much higher level It can be parsed, and it expresses the flow of control through the design. The inner syntax: It is application dependent, informal and in plan English.

  27. OUTER SYNTAX • PDL enforces structure programming, it provides set of outer syntax statements: • Sequence • Statements are separated by semi-colons, written in the order of the desired order of execution. • Handling (command); • Read_next_file;

  28. OUTER SYNTAX • Selection Statements • IF Statement • IF <condition> THEN < statement1> ELSE <statement 2>; • ENDIF; • CASE Statement • CASE <expression> • <value 1> : <statement 1>; • . • <value j> : <statement j>; • OTHERWISE <statement j+1>; • END CASE;

  29. OUTER SYNTAX • Selection Statements • IF command valid THEN determine command_type; • ELSE report error; • ENDIF; • CASE command_type; • AN : perform analysis; • ST : provide statistics; • RE : provide report; • SA : save information; • OTHERWISE report system error; • END CASE;

  30. OUTER SYNTAX • Repetition • WHILE <condition> DO; • <statement> • ENDDO; • DO • <statement> • UNTIL <condition> • FOR < variable>=<expression 1> TO<expression 2> STEP • < expression 3>; • <statement>; • ENDFOR;

  31. OUTER SYNTAX • Construct to Leave a Loop • There two ways to exit a loop: when the condition is satisfied or current status value reaches the limit. Two control statements are used: LEAVE and CYCLE • WHILE there are more record to process; • process(record); • IF process successful THEN compile update; • ELSE CYCLE; • ENDIF; • IF no more record THEN LEAVE; • ENDWHILE; • However, it can be done in: • WHILE not empty record …. • ….. • ENDWHILE

  32. OUTER SYNTAX • Assignment • <variable>:= <expression>; • first entry := name of project; • next free element address:= relative address + base register;

  33. OUTER SYNTAX • Procedures, Operations, and Functions • For procedures, we simply write their name, followed by actual parameters. Alternative way is to use CALL. • Functions are used within the expression. • Handle (command); - procedure • CALL parser(line); - procedure • token:= next_token(line); - function • port_connect(port2); - procedure

  34. OUTER SYNTAX • Type, Variable, Constant Declaration • PDL uses type,variable, constant declaration statements to define data abstraction. • TYPE semaphore; • special variable with two operations P,V • only use for synchronization • END_TYPE; • VAR sem-driver, sem_quene: semaphore; • CONS size_of_symbol_table;

  35. EXAMPLE OF ALGORITHM How to Divide - informal problem description is: given M and N, find the quotient and remainder when M is divided by N A more formal precise specification for the above problem is: Specification : given integers M 0 and N > 0, find integers Q and R such that M = QN + R and 0 R < N. (Q is the quotient and R is the remainder).

  36. DIVISION ALGORITHM 1. R: = M; 2. Q: = 0; 3. if R < N the goto step 7; 4. R: = R -N; 5. Q: = Q +1; 6. goto step 3; 7. stop R:= M; this step is not ‘R equal to M’ but as an assignment. “R is assigned M” or “R gets M” In fact, it is not a good algorithm and not even structured programming as goto statement is used.

  37. REVISED DIVISION ALGORITHM Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2)

  38. REVISED DIVISION ALGORITHM Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2) Consider (1) first, 1. It is a property of the while loop that its termination condition is false when the loop terminates. When the program terminates, R  N is false and so R < N must be true. 2. The first assignment sets R:=M and from the specification, M  0. Thus, R  0 initially. 3. The assignment R:= R -N is ‘guarded’ by the while condition R  N. This assignment can’t make R negative. Consequently, when the program terminates, 0  R < N .

  39. REVISED DIVISION ALGORITHM If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2) Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end Consider (2), After executing Q:=0; R:=M; we have Q =0 and R=M and therefore M = 0*N + M = QN +R Since the loop condition (the predicate is true), we execute Q:= Q +1; and R:= R-N; we use R’ and Q’ be the value of R and Q after assignment, we have R’ = R -N and Q’ = Q +1 ( Q = Q’-1, R = R’+N ) Before the execution of the loop M = QN + R After the execution of the loop M = (Q’-1)N + (R’ + N ) = Q’N + R’ (2) is true before the execution of the assignment, and it still be true after the assignment with new Q and R, it will be true when the program terminates. We call (2) an invariant of the loop. Since both (1) and (2) are true, the program meets the specification.

  40. REVISED DIVISION ALGORITHM Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2)

  41. REVISED DIVISION ALGORITHM {M  0, N > 0} -- pre-condition Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end {0 R < N, M = QN + R}-- post-condition

  42. REVISED DIVISION ALGORITHM {M  0, N > 0} -- pre-condition . {0 R < N, M = QN + R}-- post-condition precondition: it states the condition under which the program will work correctly, or called the domain of the program postcondition: it states relations that are true at the specified place in the computation. That is the end of the while loop. Invariant: the condition that does not change within the loop

  43. LOOP DESIGN X; while B /* I */ Y; X is the sequence of steps which initializes the loop. Y is the sequence of steps which constitute the body of the loop. !B is the termination condition and I is the invariant 1. Decide what the loop is supposed to accomplish, i.e., the postcondition. Express the postcondition in the form of I &&!B 2. Code X which establishes I 3. Design code for Y which must maintain I and make progress towards the goal, i.e. , to make B false.

  44. EXAMPLE Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2) precondition: given M  0 and N > 0 postcondition (1) and (2) B is R  N, !B is R < N, so the postcondition I && !B is R<N && M=QN+R, that is conditions (1) and (2)

  45. EXAMPLE Q: = 0; R: = M; while R  N do begin Q: = Q +1; R: = R - N; end If the algorithm is correct, the final values of Q and R will satisfy the conditions 0 R < N (1) M = QN + R (2) The loop terminates when both (1) and (2) are true. Thus the program meets it specification.

  46. MORE ON ALGORITHM Multiplication Given two integers M  0 and N, find MN. More precisely, we want to establish the postcondition p = MN (c) We need to have an equation which (a). has more variables (b). can be established easily (c). simplifies to (1) with appropriate value of the variables.

  47. MULTIPLICATION Consider the equation xN + p = MN (2) For (a), it has more variables ( x and p ) When x is M, and p = 0, then (2) satisfies the condition (b). It satisfies (c) as it simplifies to (1) when x=0, and p = MN. It is obvious that let x be M, and reducing x accordingly. Terminating when x =0.

  48. MULTIPLICATION ALGORITHM x := M; p:= 0; and reducing x accordingly. Terminating when x =0. We must maintain the invariant xN + p = MN, throughout the process. The complete program : x:= M; p:= 0; while x  0 do begin x:= .. p:=… end

  49. MULTIPLICATION ALGORITHM One way to do that is by reducing x by 1 at a time. let x’ and p’ be the new value of x and p inside the loop. We require: xN + p = MN and x’N + p’ = MN Let x’= x-1, then (x-1) N + p’ = MN simplifies xN + (p’-N) = MN That is p = p’ - N It gives p’ = p +N

  50. MULTIPLICATION ALGORITHM The complete program : x:= M; p:= 0; while x  0 do begin x:= x - 1; p:= p + N; end When this algorithm terminates, we have x =0 and xN + p = MN from which we can easily infer p = MN as required by (1) , the post condition.

More Related