Concepts • Module is a responsibility assignment rather than a subprogram. • Module specification = its inputs, its outputs its interfaces • Small enough and simple enough to be thoroughly understood • Independent development of modules • Comprehensibility: they makes easy to understand parts, connections, and the whole. • Unit Testing: Module or Function?
Decomposing Systems into Modules (1972) On the Criteria To Be Used in Decomposing Systems into Modules D.L. Parnas Communications of the ACM April 1972 Pioneer of software engineering ACM Fellow Developed the concept of information hiding
Decomposing Systems into Modules (1972) • modularization = design decisions / independent modules • modularization improves flexibility and comprehensibility • What is a module? • What criteria to use in dividing the system into modules?
• What criteria to use? • Niklaus Wirth. • Information Hiding - Input Format, Data Storage, etc. • A data structure, its internal linking, accessing procedures and modifying procedures are part of a single module • The sequence of instructions necessary to call a given routine and the routine itself are part of the same module. • What is the difference of Function vs Module? • What is the difference of Task vs Responsibility?
Wirth + Parnas • Niklaus Wirth. • Decomposition of a system into modules based on a flowchart. • Each major step in the process a module. • Begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others. • In some cases modules will not correspond to steps in the processing.
Test Yourselves: Problem Traveling salesman problem (TSP) Given a set of n nodes and distances for each pair of nodes, find a roundtrip of minimal total length visiting each node exactly once.
Test Yourselves: Problem Traveling salesman problem (TSP) Given a set of n nodes and distances for each pair of nodes, find a roundtrip of minimal total length visiting each node exactly once.
Test Yourselves: Data § Symmetric The distance from node i to node j is the same as from node j to node i. http://www.math.uwaterloo.ca/tsp/world/countries.html 29 cities - 71,009 cities
Test Yourselves: Data § Symmetric The distance from node i to node j is the same as from node j to node i. http://www.math.uwaterloo.ca/tsp/world/countries.html 29 - 71009 § Asymmetric The distance from node i to node j and the distance from node j to node i may be different. http://elib.zib.de/pub/mp-testdata/tsp/tsplib/atsp/index.html 17 to 443
Test Yourselves: Solution It is an NP-hard problem. Do not worry for an optimal solution a) Calculate and report the total distance for a dummy route as city1, city2, city3, city4, … b) Calculate and report the total distance using a greedy algorithm (nearest-neighbors) or any other fancy solution (2-opt, genetic algorithm, etc.) city1, city2, city3, city4, …
Test Yourselves: Software § Information Hiding... How? § Stepwise refinement… How? § How many modules / functions? Why ? § How they will be connected (who call who? Who needs who?) Why ? § Which is the largest file (symmetric and asymmetric) that your solution can process? Can you improve that? How? § Your program should stop (by itself) in 300 seconds. § Sequential solution is acceptable, but challenge yourselves to use at least threads (CPU) or go for GPU programming
Homework Submit to Canvas (individually): a) Source Code – one file (kind of structural programming). C, C++, Java, are OK. b) A PDF file a paper describing § your code and how did you apply Wirth and Parnas ideas a.k.a. functional decomposition and information hiding. § Screenshot with the output for small, medium, and stop scenario § A conclusion addressing the quality of your solution PS. showcase your skills for readability (make your code easy to read)