SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Restructuring
Improving the modularity of an existing code-base
                  Chris Chedgey
                   Structure101
Structure101 - People
•   Chris Chedgey, Dunmore East, Ireland
•   Paul Hickey, Toulouse, France
•   Paul O’Reilly, Enniscorthy, Ireland
•   Raghvendra Sahu, Delhi, India
•   + 3 contractors
•   No VC’s, no suits
Structure101 - Products
•   Restructure101
      •   Fix architecture
•   Structure101
      •   Define it
•   Structure101 Build
      •   Enforce it
•   Java, .NET, C/C++, Actionscript, php, …
•   1,000’s users in 100’s companies
Topics

•   What is “Restructuring”?
•   Motivation
•   Understanding structure
•   Restructuring strategies
•   Examples
What is restructuring?
Refactoring                           Restructuring
•   “Changing code without            •   “Reorganizing a code-base
    modifying behavior to improve         without modifying the code to
    nonfunctional attributes.”            improve modularity”
•   Code is readable                  •   Code-base is understandable
•   A lot of invasive code editing    •   Minimal invasive code editing
•   Scope: small worlds of a few      •   Scope: whole code base; what
    classes at a time; what you see       you don’t see in the IDE
    in the IDE.
What is structure?

•   Composition
•   Dependencies that roll up through composition
•   Nested “levels”
•   Quality factors
      •   1. Complexity           Complexity        Modularity
      •   2. Modularity
Why is structure important?
•   Determines cost of development
      •   Understandability

•   Predictable impact of changes
•   Testability
•   Reusability
•   Value of your code base
      •   Asset or liability?
Structural quality 1: complexity
•   Fat                                  •   Eliminate tangles by putting
                                             everything in one place -
      •   Too much stuff in one place        creates fat
          (method, class, package,
          bundle, …)                     •   Eliminate fat by simplistically
•   Tangles                                  partitioning fat items – creates
                                             tangles
      •   Cyclic dependencies
      •   Cumulative Component
          Dependency (CCD, Lakos)        Checked
          goes through the roof          automatically
      •   Acyclic Dependency Principle
          (ADP, Bob Martin) – morning
          after syndrome
Structural quality 2: modularity
•   High cohesion          •   S/W-eng 101
•   Low coupling           •   We ALL know about
                               modularity!
•   Information hiding
•   Interfaces
                           Checked
•   Clear responsibility
                           by human architect
•   …
Working with structure – core features
•   Composition + Dependency
•   Flow of dependency
•   Whole codebase
•   Filtering
•   Summarizing
•   Comprehension
Working with structure

•    Lists and treeview
•    Directed graph
•    Dependency Structure Matrix (DSM)
•    Levelized Structure Map (LSM)
Working with structure: list & treeview
•   Good to discover specific
    information
•   No dependency flow,
    manipulation
Visualizing structure: directed graphs
•   Info points: #items + #deps
•   Levelizable – good flow
•   #deps becomes a problem
      •   Indicate fat, not fix

•   Infinite nesting not feasible
•   Local comprehension, not for
    global/manipulation
Visualizing structure: DSM
•   Info points: #items2
•   “Scalable” - can be rendered for
    v large graphs
•   Infinite nesting possible
•   Whole code-base
•   Manipulation possible
•   Grow v large
•   Hard to read, bad for the neck
Visualizing structure - LSM
•   Info points: #items
•   Composition, dependency,
    flow, whole codebase,
    filtering, summarizing
•   Goldilocks – designed
    specifically for restructuring
The modularity wasteland
•   Methods ok
•   Classes ok
•   Handfuls of classes ok
       •   Overlapping “small worlds”
       •   Plenty of guidelines
       •   Smells and refactoring
•   But almost no logical organization
    of classes into higher level
    modules
•   This is not scalable
“But we use Java packages!”
•   Bollox!!
•   Hierarchical ok
•   Support visibility ok
•   BUT: used like a filesystem, not as an
    embodiment of module hierarchy
        •   Composition only

        •   No consideration of dependencies

        •   Little consideration of visibility

        •   Too easy to change (without rules/tools)

•   Becomes a big tangled mess
Modularity stops at class level?
•   Finite aggregation is not
    scalable
•   Oceans of classes
•   Still need to divide and
    conquer
•   Even more – affects the
    whole team
•   Is it inevitable?
Inevitable?
•   No!
•   Spring:
Restructuring strategies
•   Merge parallel structure      •   Do as much as possible by
                                      moving classes and packages
•   Top-down or bottom-up
    decision                      •   Divide disjoint packages early
•   Tackle complexity before      •   Break up v. fat classes and
    modularity                        packages early
•   Break v large class tangles   •   Disentangle
    early
                                  •   Consider mixed granularity
•   Address tangles top-down
                                  •   …
Merge parallel structures
•   Common to separate interfaces/api
    from implementation
•   Perhaps attempt to increase
    awareness of visibility
•   Obscures module structure esp if
    higher in hierarchy
•   Better to consider module sub-items
    as siblings with visibility
•   Keep both if there is a strong
    need/desire for physical code to be
    separate
•   Use of transformations
Merge parallel structures
Bust v large class tangles early
•   Often there is 1 or a few v.large        •   Can the class tangle be contained
    tangles spanning many packages               within a single package?
       •   Making those packages acyclic            •   At least for now?
           means busting the class tangle
                                                    •   Not if classes span to much of the
•   Does it span multiple higher-level                  layering
    layers?
                                                    •   Not if it represents a significant
       •   Break the feedback dependencies              portion of your code base
           between the layers
                                             •   Can you break the tangle into several
                                                 acyclic subsets of tangles?
                                                    •   Each subset can be contained within
                                                        a single package
                                             •   Each subset can be contained within a
                                                 narrow range of ideal leveling
Do as much as you can by moving
classes/packages first
•   Low effort refactoring
•   Less invasive surgery so less risk of impacting behavior
•   Exception – static classes
•   Biggest bang for the buck, unless there are v.large class tangles
•   Option to manage architecture separate from physical code
      •   Map classes to physical components
      •   Can’t be done if model requires invasive class editing
Top-down or bottom-up?
•   Top-down                                     •   A bit of both
      •   Preserves as much of the package              •   Preserve top-level breakout
          hierarchy as possible
                                                              •   May reflect team structure
      •   Team can still find classes
                                                              •   Often reflects initial architecture
      •   Feasible if the target structure is
                                                                     •   Sub-modules were not explicitly
          close to the current                                           designed

•   Bottom-up                                           •   Preserve in regions where there is
                                                            relatively small amount of
      •   Current packaging is of little use                restructuring
      •   Target structure is far from current
      •   Often easiest to implement
Make items only using or used by a tangle
Move only used/using child items
Split disjoint packages
Split fat packages and classes
Move feeback from/top
Move feedback to/bottom
Move tangles together
Tackle complexity before (other)
modularity
•   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
•   Good basis for further modularization (coupling, cohesion,
    interfaces, …)
Summary
•   The modularity wasteland is normal
•   It costs
•   It can be salvaged
•   It is not easy, but the returns can be huge
•   Questions?
•   Thank you!

Más contenido relacionado

Similar a Restructuring Code for Improved Modularity

SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSkillwise Group
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1Julie Iskander
 
Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Chris Chedgey
 
Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Chris Chedgey
 
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeByron Miller
 
Docker in the Enterprise
Docker in the EnterpriseDocker in the Enterprise
Docker in the EnterpriseSaul Caganoff
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayTony Ng
 
Tool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesTool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesCodeOps Technologies LLP
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Heartin Jacob
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutionsSangjin Lee
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock Steve Barbour
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureAttila Bertók
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesYoav Francis
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Factory and Class Cluster
Factory and Class ClusterFactory and Class Cluster
Factory and Class ClusterHSIEH CHING-FAN
 

Similar a Restructuring Code for Improved Modularity (20)

SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)Bridging the divide between architecture and code (US version)
Bridging the divide between architecture and code (US version)
 
Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)Bridging the Divide between Architecture and Code (Germany JUGs version)
Bridging the Divide between Architecture and Code (Germany JUGs version)
 
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet CodeATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
ATXPUG Meetup 11/11/14 - Managing complexity in Puppet Code
 
Docker in the Enterprise
Docker in the EnterpriseDocker in the Enterprise
Docker in the Enterprise
 
Calling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBayCalling All Modularity Solutions: A Comparative Study from eBay
Calling All Modularity Solutions: A Comparative Study from eBay
 
Shooting at a Moving Target
Shooting at a Moving TargetShooting at a Moving Target
Shooting at a Moving Target
 
Tool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesTool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large Codebases
 
Week4 grasp-into
Week4 grasp-intoWeek4 grasp-into
Week4 grasp-into
 
Hpts 2011 flexible_oltp
Hpts 2011 flexible_oltpHpts 2011 flexible_oltp
Hpts 2011 flexible_oltp
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)
 
Calling all modularity solutions
Calling all modularity solutionsCalling all modularity solutions
Calling all modularity solutions
 
Architecture Principles CodeStock
Architecture Principles CodeStock Architecture Principles CodeStock
Architecture Principles CodeStock
 
Onion Architecture / Clean Architecture
Onion Architecture / Clean ArchitectureOnion Architecture / Clean Architecture
Onion Architecture / Clean Architecture
 
CAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and PracticesCAP Theorem - Theory, Implications and Practices
CAP Theorem - Theory, Implications and Practices
 
Week5 inhertiance
Week5 inhertianceWeek5 inhertiance
Week5 inhertiance
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Factory and Class Cluster
Factory and Class ClusterFactory and Class Cluster
Factory and Class Cluster
 

Más de Chris Chedgey

Monolith to Modular - The devil in the dependencies
Monolith to Modular - The devil in the dependenciesMonolith to Modular - The devil in the dependencies
Monolith to Modular - The devil in the dependenciesChris Chedgey
 
Rediscovering Modularity - .NET Edition
Rediscovering Modularity - .NET EditionRediscovering Modularity - .NET Edition
Rediscovering Modularity - .NET EditionChris Chedgey
 
Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012Chris Chedgey
 
Retrofitting Architecture - Oredev 2012
Retrofitting Architecture - Oredev 2012Retrofitting Architecture - Oredev 2012
Retrofitting Architecture - Oredev 2012Chris Chedgey
 
Rediscovering Modularity - JFall 2012 version
Rediscovering Modularity - JFall 2012 versionRediscovering Modularity - JFall 2012 version
Rediscovering Modularity - JFall 2012 versionChris Chedgey
 

Más de Chris Chedgey (6)

Monolith to Modular - The devil in the dependencies
Monolith to Modular - The devil in the dependenciesMonolith to Modular - The devil in the dependencies
Monolith to Modular - The devil in the dependencies
 
Beautiful Structure
Beautiful StructureBeautiful Structure
Beautiful Structure
 
Rediscovering Modularity - .NET Edition
Rediscovering Modularity - .NET EditionRediscovering Modularity - .NET Edition
Rediscovering Modularity - .NET Edition
 
Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012Rediscovering modularity - JavaOne Brazil 2012
Rediscovering modularity - JavaOne Brazil 2012
 
Retrofitting Architecture - Oredev 2012
Retrofitting Architecture - Oredev 2012Retrofitting Architecture - Oredev 2012
Retrofitting Architecture - Oredev 2012
 
Rediscovering Modularity - JFall 2012 version
Rediscovering Modularity - JFall 2012 versionRediscovering Modularity - JFall 2012 version
Rediscovering Modularity - JFall 2012 version
 

Último

A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 

Último (20)

A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 

Restructuring Code for Improved Modularity

  • 1. Restructuring Improving the modularity of an existing code-base Chris Chedgey Structure101
  • 2. Structure101 - People • Chris Chedgey, Dunmore East, Ireland • Paul Hickey, Toulouse, France • Paul O’Reilly, Enniscorthy, Ireland • Raghvendra Sahu, Delhi, India • + 3 contractors • No VC’s, no suits
  • 3. Structure101 - Products • Restructure101 • Fix architecture • Structure101 • Define it • Structure101 Build • Enforce it • Java, .NET, C/C++, Actionscript, php, … • 1,000’s users in 100’s companies
  • 4. Topics • What is “Restructuring”? • Motivation • Understanding structure • Restructuring strategies • Examples
  • 5. What is restructuring? Refactoring Restructuring • “Changing code without • “Reorganizing a code-base modifying behavior to improve without modifying the code to nonfunctional attributes.” improve modularity” • Code is readable • Code-base is understandable • A lot of invasive code editing • Minimal invasive code editing • Scope: small worlds of a few • Scope: whole code base; what classes at a time; what you see you don’t see in the IDE in the IDE.
  • 6. What is structure? • Composition • Dependencies that roll up through composition • Nested “levels” • Quality factors • 1. Complexity Complexity Modularity • 2. Modularity
  • 7. Why is structure important? • Determines cost of development • Understandability • Predictable impact of changes • Testability • Reusability • Value of your code base • Asset or liability?
  • 8. Structural quality 1: complexity • Fat • Eliminate tangles by putting everything in one place - • Too much stuff in one place creates fat (method, class, package, bundle, …) • Eliminate fat by simplistically • Tangles partitioning fat items – creates tangles • Cyclic dependencies • Cumulative Component Dependency (CCD, Lakos) Checked goes through the roof automatically • Acyclic Dependency Principle (ADP, Bob Martin) – morning after syndrome
  • 9. Structural quality 2: modularity • High cohesion • S/W-eng 101 • Low coupling • We ALL know about modularity! • Information hiding • Interfaces Checked • Clear responsibility by human architect • …
  • 10. Working with structure – core features • Composition + Dependency • Flow of dependency • Whole codebase • Filtering • Summarizing • Comprehension
  • 11. Working with structure • Lists and treeview • Directed graph • Dependency Structure Matrix (DSM) • Levelized Structure Map (LSM)
  • 12. Working with structure: list & treeview • Good to discover specific information • No dependency flow, manipulation
  • 13. Visualizing structure: directed graphs • Info points: #items + #deps • Levelizable – good flow • #deps becomes a problem • Indicate fat, not fix • Infinite nesting not feasible • Local comprehension, not for global/manipulation
  • 14. Visualizing structure: DSM • Info points: #items2 • “Scalable” - can be rendered for v large graphs • Infinite nesting possible • Whole code-base • Manipulation possible • Grow v large • Hard to read, bad for the neck
  • 15. Visualizing structure - LSM • Info points: #items • Composition, dependency, flow, whole codebase, filtering, summarizing • Goldilocks – designed specifically for restructuring
  • 16. The modularity wasteland • Methods ok • Classes ok • Handfuls of classes ok • Overlapping “small worlds” • Plenty of guidelines • Smells and refactoring • But almost no logical organization of classes into higher level modules • This is not scalable
  • 17. “But we use Java packages!” • Bollox!! • Hierarchical ok • Support visibility ok • BUT: used like a filesystem, not as an embodiment of module hierarchy • Composition only • No consideration of dependencies • Little consideration of visibility • Too easy to change (without rules/tools) • Becomes a big tangled mess
  • 18. Modularity stops at class level? • Finite aggregation is not scalable • Oceans of classes • Still need to divide and conquer • Even more – affects the whole team • Is it inevitable?
  • 19. Inevitable? • No! • Spring:
  • 20. Restructuring strategies • Merge parallel structure • Do as much as possible by moving classes and packages • Top-down or bottom-up decision • Divide disjoint packages early • Tackle complexity before • Break up v. fat classes and modularity packages early • Break v large class tangles • Disentangle early • Consider mixed granularity • Address tangles top-down • …
  • 21. Merge parallel structures • Common to separate interfaces/api from implementation • Perhaps attempt to increase awareness of visibility • Obscures module structure esp if higher in hierarchy • Better to consider module sub-items as siblings with visibility • Keep both if there is a strong need/desire for physical code to be separate • Use of transformations
  • 23. Bust v large class tangles early • Often there is 1 or a few v.large • Can the class tangle be contained tangles spanning many packages within a single package? • Making those packages acyclic • At least for now? means busting the class tangle • Not if classes span to much of the • Does it span multiple higher-level layering layers? • Not if it represents a significant • Break the feedback dependencies portion of your code base between the layers • Can you break the tangle into several acyclic subsets of tangles? • Each subset can be contained within a single package • Each subset can be contained within a narrow range of ideal leveling
  • 24. Do as much as you can by moving classes/packages first • Low effort refactoring • Less invasive surgery so less risk of impacting behavior • Exception – static classes • Biggest bang for the buck, unless there are v.large class tangles • Option to manage architecture separate from physical code • Map classes to physical components • Can’t be done if model requires invasive class editing
  • 25. Top-down or bottom-up? • Top-down • A bit of both • Preserves as much of the package • Preserve top-level breakout hierarchy as possible • May reflect team structure • Team can still find classes • Often reflects initial architecture • Feasible if the target structure is • Sub-modules were not explicitly close to the current designed • Bottom-up • Preserve in regions where there is relatively small amount of • Current packaging is of little use restructuring • Target structure is far from current • Often easiest to implement
  • 26. Make items only using or used by a tangle
  • 27. Move only used/using child items
  • 29. Split fat packages and classes
  • 33. Tackle complexity before (other) modularity • 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 • Good basis for further modularization (coupling, cohesion, interfaces, …)
  • 34. Summary • The modularity wasteland is normal • It costs • It can be salvaged • It is not easy, but the returns can be huge • Questions? • Thank you!

Notas del editor

  1. Guten abendIch bin ein berlinerDarmstadterGood few years agoBit for freedomLast bit of useless info We dev tools – talk not about these – talk after formal pres
  2. 6 components to the company, 4 human, 2 beautifulWe don’t own suitsLove what we doRelentless innovation to solve a big problem
  3. What – relate to refactoringMotivation – modularity/scalabilityUnderstanding – quantifying over complexityRestructuring strategies – emerging from experience, dozens of client engagements and use casesShow parts of products to illustrate principles, not a tutorial on the products
  4. Don’t care whether you use inheritance or aggregationThink of a mass of lines of code, currently organized in one way into methods, classes, packages – we want to reorganize the same lines of code into a different hierarchy of methods, classes, packages.
  5. Can you test a tangle of hundreds of classes?Can’t reuse subsets if everything uses everythingWhen a code-base becomes a liability, sw-engineering has failed
  6. Structural complexity can be assigned thresholds and checked objectively/automatically
  7. We learn about modularity in SW-eng101Builds on complexity principles
  8. Another representation of a graphManipulation involves dragging rows and columns around