Embed Size (px)
Transcript of Rediscovering Modularity
- 1. Rediscovering ModularityChris ChedgeyStructure101Gearconf 2012 Dusseldorf
2. Summary We do modularity at implementation levels (classes) We dont 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 3. Modularity divide and conquer High cohesion S/W-eng 101 Low coupling Eng-101 Abstraction Human-101 !! Information hiding We ALL know about modularity! Interfaces Clear responsibility 4. Levels of code qualityPhysicalImagination or LogicalVisualizationClasses FunctionsAttentionLines of code 5. The modularity wasteland Methods ok Classes ok Handfuls of classes ok But almost no logicalorganization of classes intohigher level abstraction This is not scalable 6. 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) 7. 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? 8. Solutions? Do nothing different or Restructure or Rebuild 9. What is restructuring?Refactoring Restructuring Changing code without Reorganizing a code-basemodifying behavior to improvewithout modifying the code tononfunctional attributes. improve modularity Cost of Code is readabledevelopment Code-base is understandable A lot of invasive code editing Minimal invasive code editing Scope: small worlds of a fewScope: whole code base; whatclasses at a time; what you seeyou dont see in the IDEin the IDE. 10. Step 1: Levelization Remove tangles Balance Cyclic dependencies Eliminate tangles by puttingeverything in one place - creates Without fat fat Too much complexity in one place (method, class, package, Eliminate fat by simplistically bundle, ) partitioning fat items createstanglesCheckedautomatically 11. 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 12. 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 13. 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 14. 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 15. More restructuring strategies Levelize first Divide disjoint packages early Break v large class tangles early Break up v. fat classes andpackages early Top-down or bottom-up decision Consider mixed granularity Do as much as possible bymoving classes and packages Merge parallel structure Address tangles top-down 16. Summary We do modularity at implementation levels (classes) We dont 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: Levelizationvote.jax-awards.com 17. Thank you! Questions?