Pietro Di Bello
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Continued Learning - The Beauty of Maintenance - Kent Beck - DDD Europe 2020 disqus: pierodibello --- ###### tags: `coupling` `cohesion` `design` `agile` `kentbeck` # Continued Learning: The Beauty of Maintenance - Kent Beck - DDD Europe 2020 https://www.youtube.com/watch?v=3gib0hKYjB0 {%youtube 3gib0hKYjB0 %} ## Public speaking Nervousness (playing live on stage) or excitement (waiting to open the present at Xmas morning) both share the same sensations: you have to choose how you want to live that moment... you could choose nervousness or excitement. Choose excitement, the joy of discovering (see [A Soprano on her head](https://www.amazon.it/Soprano-Her-Head-Right-Side-Up-Performances/dp/0911226214)). ## Coupling and Cohesion **Coupling** and **Cohesion** are foundational concepts, but everyone means something a little different. People tend to use those two words to describe things that are not related to coupling and cohesion (and maybe we should find a proper word for those things, instead of using coupling and cohesion...). The "Structured Design" book (by Ed Yourdon and Larry Constantine) introduced the concepts of Coupling and Cohesion. ![](https://i.imgur.com/JJmYHX3.png) Ed and Larry: *What are the common properties of programs that are cheap to change: are there any patterns?* 🤔 ### Building sw is not like building a car :computer: != :car: Building sw is not like building a car: we cannot spend 70% of the budget on car maintenance, but on sw this could be easily true. Sw changes as soon as it gets created and released in the hand of the users! In XP, we say we want to spend 99% on maintenance: we'll just get it in production and then build it up from there 😀 ### Coupling #### The original definition of Coupling Software is built out of elements (elements may be at different scales: from variables, to statements, functions, methods, components, repositories, to services). If I have two elements, A and B, and I say that **"A and B are coupled"** `A --- B` this means that **if I change A I also have to change B**. The original definition of coupling is: :::info **A and B are coupled *with respect to a particular change* if changing A implies changing B** ::: `Coupled(A,B, ∆) :: ∆A -> ∆B` ![](https://i.imgur.com/TSu1H3J.png) #### Coupling between services If I have two **services** and one calls the other, they're not coupled by this definition (unless if I change one I have to change the other too)... they have some relationship though (are we missing a word here?). :::warning The key words when talking about coupling is **"...are coupled WITH RESPECT TO `<SOMETHING>`"** ::: E.g. two services are coupled with respect to name changes of the parameters. #### The Parallel pattern - making things worst and then making them better To make a change without breaking other dependent elements, have two implementations of the same thing and slowly move from using the old one to using the new one. When finally nobody uses the old implementation anymore, just delete it. ![](https://i.imgur.com/tHM7nQB.png) "Isn't this weird?" some people think... _making things worst and then making them better_?! No, it isn't * life lesson #1 things always get worse before they get better * life lesson #2 you can do it #### Why coupling is important? Because of cost. :::info The cost of software is roughly equivalent to the cost of change. ::: That's why we spend most of the money of sw development on maintenance. All changes don't cost the same amount... :::info The cost of change is roughly equivalent to the cost of BIG changes. ::: ![](https://i.imgur.com/OJgo7H6.png) we're gonna have * lots and lots of small changes that are cheap * few big changes that are really expensive What makes changes really expensive is not just the change, it's the **"cascading", ripple effect** like in _I change this, so I have to change those too, so now I also have to change those, and now I have to change those, ..._ ![](https://i.imgur.com/jp4q3rb.png) Complexity theory => power law distribution, like in avalanches or hurricanes. The more changes we have: * the more small changes we'll have * the more big changes we'll have, that will compound and bring the cost of change higher In sw, **what conducts the cost of a change is COUPLING** and its "cascading changes" effect. A big percentage of cost of change is in the few big changes (the "tail" of the curve). ![](https://i.imgur.com/3xbNNIu.png) So, the less coupled your system is, the less likely the changes will propagate, the less extreme the cost of these most expensive changes will be, the longer you can last continuing to change your software. :::success Decoupling things reduces the cost of making changes over time ::: Side note: there will always be some coupling in your system! #### Coupling can happen anywhere! Coupling is not just "this function call that function", coupling can happen anywhere! There is a non-zero chance that any change you make is going to break something somewhere else... the more complex the system, the more likely this will happen. True story at Facebook: two unrelated services hosted on the same rack, one changed its backup policy, this in turn saturated the rack network switch => these two services were coupled with respect to the backup procedures! #### Principles to reduce coupling At the level-code principles you can see the patterns in the ["Smalltalk best practices"](https://www.amazon.it/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X) and ["Implementation patterns"](https://www.amazon.it/Implementation-Patterns-Kent-Beck/dp/0321413091) books. :::danger The most expensive coupling is the coupling that you don't see! ::: (like the two services sharing a rack switch). Expert programmers have "good habits", like **don't use global state**, and **be explicit of the data that goes in and data that goes out** => you can see clearly what enters, what exits => it's then easier to identify coupling. ### Cohesion (inverse of coupling?) ![](https://i.imgur.com/5lOBszf.png) **The original definition of Cohesive:** If I have an element E that have sub-elements, that element is **cohesive** to the degree that its sub-elements are coupled, meaning that if I have to change one of these sub-elements, I have to change the others sub-elements at the same time too. **Putting together things that change together is a way of reducing the scope of coupling**, because the rippling effect will be localized in a single element, and it will be also easier to find where to make the change, because the elements to change will be in the same place. #### Degree of cohesion All sub-elements should be coupled to each other? Or it's enough to have at least SOME sub-elements coupled? It depends. If all sub-elements are coupled, code will be easier to change. For example, having two out of four sub-elements coupled seems good enough for a cohesive element, but it's then better to keep together the sub-elements that change together and separate those that don't. You'll end up with a more cohesive solution, that will make changes easier, because you'll know that when you change one sub-element you have to change the other sub-element and you can forget the other sub-elements. ![](https://i.imgur.com/rYYSVQ6.png) ### Coupling vs Cohesion Eliminating coupling is hard, improving cohesion is simpler! :::info There is always a trade-off between the cost of coupling ("rippling changes") and the cost of de-coupling. 🙅‍ ::: Since there is always some coupling in your system, you have to continuously balance between: * **the cost of coupling** that you're experiencing because of the changes you have to do, and * **the cost of decoupling** the system ![](https://i.imgur.com/WYw6ZRF.png) > :question: what should be the "right" curve for the cost of decoupling? the light green one or the dark green one? ## Should I tidy first? When should I decouple? Should I tidy first? In front of a change I need to make, should I reduce coupling / improve cohesion first or just make the change to the ugly code? This is a call that we - as engineers - have to make every time. Coupling is a `n^2` problem: every element in your system can be coupled to every other elements in the system (where `n` is the number of services, repositories, variables, modules, classes, etc). And `n` can be very large! The cost of decoupling can be enormous. The good news is that **you can always find elements to make more cohesive**. And making code more cohesive (take things that are going to change at the same time and putting them together) can be done locally, without having to look at the entire system. Extract method, make the change, inline (or not). ## Two style of designers: [lumpers and splitters](https://kentbeck.substack.com/p/lumpers-and-splitters) * **splitters**: prefer lots of little pieces that interact with each others * **lumpers**: prefer big giant elements (classes, tables, methods) so that they can see all at one glance > see also https://kentbeck.substack.com/p/make-it-run-make-it-right :::success In order to reduce coupling over time, you may choose to create cohesion, because creating cohesion tend to reduce coupling. ::: ## Structural change vs Behavioral change (make the change easy, then make the easy change) You have an idea, so you change the behavior to implement that idea. But you also have to change the structure of the system in order to implement that idea. And how the system is structured affects the cost of changing the behavior you need, because of coupling! What do you do first then? :::info **Make the change easy, then make the easy change** ::: You decide to *first* change the structure of the system in order for the change to be easy. Making the change easy can be hard too, because you may need to do recursive things in order to make the change easy, just like the [yak shaving](https://www.urbandictionary.com/define.php?term=yak%20shaving). You're spending energy and brain power on making the next change easy, not on making the change, and this could be hard to do for many devs, because they like the "tough job" and the pressure is on "I wanna see the next behavior change". ### Carefully separate structural changes from behavioral changes Try this experiment: **[carefully separate structural changes from behavioral changes.](https://kentbeck.substack.com/p/structure-and-behavior-prs)** Either do a structural change or a behavioral change, but not the two at the same time. And keep those changes separated (e.g. in separated pull requests). Behavioral changes in general are IRREVERSIBLE, you have to be very careful. Structural changes are REVERSIBLE (extract method -> inline method). So you can apply different standards to very different sets of decisions. > see also https://kentbeck.substack.com/p/structure-and-behavior ## Waterfall is coming back, kill it again (with fire 🔥) Waterfall never works, it never did! Traits of a *"waterfallish"* way of thinking * big feedback loops * not looking for / getting feedback as soon as possible * specify all without getting feedback Big feedback loops don't work because: * you cannot predict the future * making a change in the world cause the world to change, so the next thing will be different So you cannot specify all the things, you have to do one thing, look for feedback, and then decide. ### Call a timeout In front of a "waterfallish" thinking, let's call a timeout! I'm not sure about what we did: let's implement something, let's put in front of people, let's see how they act, let's see what we learn and how this change our understanding, BEFORE taking the next decision.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully