inf 212 modularity instructors: crista lopes copyright © instructors

20
INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors.

Upload: clifton-homer-bradley

Post on 04-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

INF 212ModularityInstructors: Crista Lopes

Copyright © Instructors.

Page 2: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Outline

The 2 sides of Modularity Today:

Modularity and Style Style in the other Arts Some Styles

Page 3: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Modules as physical components

Page 4: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Modules as conceptual units

Page 5: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Software Systems – Your Brain...

Page 6: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Software Systems – Your Code...

Page 7: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Your brain and Your code

Expression of thoughts using PLSuggestion for thoughts

Page 8: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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.

Page 9: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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...

Page 10: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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

Page 11: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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

Page 12: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Styles in the other Arts

Pachelbel Canon in D Original 18 styles (piano) A few more (guitar)

Exercises in Style, R. Queneau

Page 13: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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

Page 14: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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

Page 15: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

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

Page 16: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Example - KWIC

Shared Data

Input Alphabetizing

Master Control

Text arrayWordindex Alphabetized

index

Page 17: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Example - KWIC

Read input

Shift Sort Displayoutput

Pipe-and-filter (functional)

Page 18: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Example - KWIC

Read input

Shift Sort Displayoutput

Monadic

Page 19: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Example - KWIC

OOP-ish (data abstraction)

Line Storage

Input

Circular Shifter

Alphabetizer

Output

Master Control

Page 20: INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors

Example - KWIC

Inputagent

Shiftagent

Sortagent

Outputagent

Pub-Sub

Event Manager

listen/announce

listen/announce

listen/announce

listen/announce