Download - Rediscovering Modularity

Transcript
Page 1: Rediscovering Modularity

Rediscovering Modularity

Chris Chedgey

Structure101

Gearconf 2012 Dusseldorf

Page 2: Rediscovering Modularity

Summary

• We do modularity at implementation levels (classes)

• We don’t do modularity at logical levels (above classes)

• This is not scalable

• We discover it is not scalable when code-base creaks

• The codebase can be salvaged (restructured)

• Step 1: Levelization

Page 3: Rediscovering Modularity

Modularity – divide and conquer

• High cohesion

• Low coupling

• Abstraction

• Information hiding

• Interfaces

• Clear responsibility

• …

• S/W-eng 101

• Eng-101

• Human-101 !!

• We ALL know about modularity!

Page 4: Rediscovering Modularity

Levels of code quality

Physical

Logical

Classes

Functions

Lines of code

Attention

Imaginationor

Visualization

Page 5: Rediscovering Modularity

The modularity wasteland

• Methods ok

• Classes ok

• Handfuls of classes ok

• But almost no logical organization of classes into higher level abstraction

• This is not scalable

Page 6: Rediscovering Modularity

Why?

• Logical design is not necessary early on – let it emerge

• In fact it might get in the way

• At some point the sea of classes is too big (50kloc?)

• This point is invariably overshot (no pain => business as usual)

• Package/namespace structures are accidental (like folders)

Page 7: Rediscovering Modularity

Symptoms… as code-base grows…

• Cost per feature increases

• Unexpected impacts of change

• Unreliable schedules

• Test cycles increase

• Reuse less

• Value of your code base declines• Asset or liability?

Page 8: Rediscovering Modularity

Solutions?

• Do nothing different

• or

• Restructure

• or

• Rebuild

Page 9: Rediscovering Modularity

What is restructuring?

Refactoring• “Changing code without

modifying behavior to improve nonfunctional attributes.”

• Code is readable

• A lot of invasive code editing

• Scope: small worlds of a few classes at a time; what you see in the IDE.

Restructuring• “Reorganizing a code-base

without modifying the code to improve modularity”

• Code-base is understandable

• Minimal invasive code editing

• Scope: whole code base; what you don’t see in the IDE

Cost of development

Page 10: Rediscovering Modularity

Step 1: Levelization• Remove tangles

• Cyclic dependencies

• Without fat

• Too much complexity in one place (method, class, package, bundle, …)

• Balance

• Eliminate tangles by putting everything in one place - creates fat

• Eliminate fat by simplistically partitioning fat items – creates tangles

Checked automatically

Page 11: Rediscovering Modularity

Unlevelized

• Acyclic Dependency Principle (ADP)

• Morning after syndrome

• Release/reuse Principle

• Abstraction, distance from the main sequence

• Clear responsibility?

• Divide and conquer?

• A tangle of items is really a single item

Page 12: Rediscovering Modularity

Levelize first

• A structure without tangles is much easier to manipulate

• A milestone in its own right

• A code-base that is much easier to understand

• Many simply focus on keeping (over-)complexity out

• Once levelized, other modularity adjustments are “easy”

Page 13: Rediscovering Modularity

Visualizing structure - LSM• Info points: #items

• Composition, dependency, flow, whole codebase, filtering, summarizing

• Designed specifically for restructuring

• Demo

• LSM

• Adjusting levelized structure

• Adjusting within tangle

Page 14: Rediscovering Modularity

Levelization

• Look at existing logical design (packages, namespaces, assemblies, …)

• Look at the raw material (classes)

• Decide top-down vs. bottom-up

• Break up very large class tangles

• Prioritize non-invasive changes

• Simulate changes before implementing

Page 15: Rediscovering Modularity

More restructuring strategies

• Levelize first

• Break v large class tangles early

• Top-down or bottom-up decision

• Do as much as possible by moving classes and packages

• Merge parallel structure

• Address tangles top-down

• Divide disjoint packages early

• Break up v. fat classes and packages early

• Consider mixed granularity

• …

Page 16: Rediscovering Modularity

Summary

• We do modularity at implementation levels (classes)

• We don’t do modularity at logical levels (above classes)

• This is not scalable

• We discover it is not scalable when code-base creaks

• The codebase can be salvaged (restructured)

• Step 1: Levelization vote.jax-awards.com

Page 17: Rediscovering Modularity

Thank you!

Questions?