Com S 362 Lecture Outline ----------------------------------------------- ABSTRACTION, DECOMPOSITION, LOCALITY, SEPARATION OF CONCERNS and MODULARITY ------------------------------------------------ READING: Dijkstra, E. W. (1982), On the role of scientific thought, in `Selected Writings on Computing: A Personal Perspective', Springer-Verlag, pp. 60--66. ------------------------------------------------- Overview of the lecture: - Programming in the large vs programming in the small - Abstraction: [Hide the unnecessary details] - Locality: [More precisely source locality] - Modularity: property of a module that enables us to understand it by looking at its implementation and the specification of other module that it uses. We [SHALL NOT] need to look at the implementation of other modules. - Decomposition - Separation of concerns ------------------------------------------------- The role of decomposition - Small programs can be implemented by one person as monolithic units - As size increases monolithic structure is no longer reasonable - Code becomes difficult to understand - Often a team is working on the program (not a single person) - Solution: Partition the program into a number of independent small programs (often called decomposition) - Desired property: People must be able to work on pieces separately How do we decompose a problem? - Each subproblem is at the same level of detail - Each subproblem can be solved independently; and - the solutions to the subproblem can be combined to solve the original problem Example: Merge sort is a sorting algorithm for rearranging lists (or any other data structure that can only be accessed sequentially, e.g. file streams) into a specified order. It is a particularly good example of the divide and conquer algorithmic paradigm. It is a comparison sort. We can decompose the problem of merge sort into the following subproblems. 1. Divide the unsorted list into two sublists of about half the size 2. Sort each of the two sublists 3. Merge the two sorted sublists back into one sorted list. ---------------------------------------------------- Role of abstraction is software development - A method to change the level of details to be considered - Many to one mapping (simplifies analysis) Abstraction by parameterization - Through the introduction of program parameters - represent possibly infinite set of computation by a single program Abstraction by specification - Abstact from the the computation, replacing it with the specification