inf 212 modularity instructors: crista lopes copyright © instructors
TRANSCRIPT
INF 212ModularityInstructors: Crista Lopes
Copyright © Instructors.
Outline
The 2 sides of Modularity Today:
Modularity and Style Style in the other Arts Some Styles
Modules as physical components
Modules as conceptual units
Software Systems – Your Brain...
Software Systems – Your Code...
Your brain and Your code
Expression of thoughts using PLSuggestion for thoughts
How to Divide the Problem?
?(*)
(*) This is not a trivial question, and you only face it much later, possiblyafter years of experience in programming.(*) Some people never even face this question, having learnt only oneway of thinking.
PLs and Modularization
PLs are the materials of expression Suggest ways of thinking, ordering,
dividing
English suggests placing adjectives before nouns E.g. “An inconvenient truth”
Latin languages suggest placing adjectives after nouns E.g. “Uma verdade inconveniente” Try doing this in English...
A very old issue
Expressing one’s thoughts using some language and materials
Understanding the deeper structures of artifacts, after analyzing them
One Word:
STYLESTYLE
STYLE
STYLESTYLESTYLE
STYLESTYLE
STYLE
PLs and Styles
PLs encourage styles of expression, sometimes quite strongly
Often the style one learns first is the one that sticks to our brain, like our mother natural language
Language wars are style wars “English is better than French” “Haskell is better than Java” More on utilitarian perspectives later on
Styles in the other Arts
Pachelbel Canon in D Original 18 styles (piano) A few more (guitar)
Exercises in Style, R. Queneau
When CS rediscovered the issue Parnas “On the criteria to be used in
decomposing systems into modules” Concrete examples and guidelines for
different ways to modularize Primarily how to deal with state
We can do it in many ways, now what? Which is better? Parnas suggestion: information hiding
should play a role in deciding that Functional programming had been
suggesting it all along without formulating the question
Modularity
Easier comprehension of complex problems
Systematic resolution: Divide-and-conquer
Loose coupling Division of labor Enables independent evolution and
maintenance Reuse
High Cohesion Module has single responsibility/purpose
Example - KWIC
Problem Input: Ordered set of lines, with ordered set
of words, with ordered set characters. Any line may be circularly shifted (removing
the last word of the line, appending at the beginning)
Output: All circular shifts of all lines in alphabetical order
Q u i c k
1 2 3 4 5
Q u i c k
1 2 3 4 5
B r o w n
1 2 3 4 5
B r o w n
1 2 3 4 5
F o x1 2 3F o x1 2 3
1 2 3
Example - KWIC
Shared Data
Input Alphabetizing
Master Control
Text arrayWordindex Alphabetized
index
Example - KWIC
Read input
Shift Sort Displayoutput
Pipe-and-filter (functional)
Example - KWIC
Read input
Shift Sort Displayoutput
Monadic
Example - KWIC
OOP-ish (data abstraction)
Line Storage
Input
Circular Shifter
Alphabetizer
Output
Master Control
Example - KWIC
Inputagent
Shiftagent
Sortagent
Outputagent
Pub-Sub
Event Manager
listen/announce
listen/announce
listen/announce
listen/announce