Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Connascence - How to detect code smell

Avatar for Thanh Thanh
November 09, 2017

Connascence - How to detect code smell

Topics covered:
- clean code
- refactoring
- software development

Avatar for Thanh

Thanh

November 09, 2017
Tweet

Other Decks in Programming

Transcript

  1. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition • (1995) Meilir Page-Jones;

    “In software engineering, two components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system.”
  2. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  3. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  4. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Direction where to refactor to
  5. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Direction where to refactor to
  6. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Three axis of connascence:

    • Strength: Stronger connascence are harder to discover, or harder to refactor • Degree: An entity that is connascent with thousands of other entities is likely to be a larger issue than one that is connascent with only a few. • Locality: Connascent elements that are close together in a codebase are better than ones that are far apart Strength Weak Strong Degree Few A lot Few A lot Locality Close Far apart
  7. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Three axis of connascence:

    • Strength: Stronger connascence are harder to discover, or harder to refactor • Degree: An entity that is connascent with thousands of other entities is likely to be a larger issue than one that is connascent with only a few. • Locality: Connascent elements that are close together in a codebase are better than ones that are far apart Direction where to refactor to Strength Weak Strong Degree Few A lot Few A lot Locality Close Far apart
  8. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Definition Three axis of connascence:

    • Strength: Stronger connascence are harder to discover, or harder to refactor • Degree: An entity that is connascent with thousands of other entities is likely to be a larger issue than one that is connascent with only a few. • Locality: Connascent elements that are close together in a codebase are better than ones that are far apart Direction where to refactor to Strength Weak Strong Degree Few A lot Few A lot Locality Close Far apart
  9. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Types of Connascences: Identity Value

    Timing Execution Order ----------------- Position Algorithm Meaning Type Name Strength Degree Locality
  10. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Types of Connascences: Identity Value

    Timing Execution Order ----------------- Position Algorithm Meaning Type Name Strength Degree Locality
  11. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Connassence of Type • Two

    components must agree on the type of something • ...it happens for strong typed languages too:
  12. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Connassence of Position • Two

    components must be adjacent or occur in a particluar order • 3 degrees of connascence
  13. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Connassence of Algorithm • Two

    components must agree on a particular algorithm - Encryption, e.g. SHA-2, SHA512, etc - Certificate
  14. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Connassence of Timing • Two

    components must agree on the timing of execution E.g. Race condition between threads
  15. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  16. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  17. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  18. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  19. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  20. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  21. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  22. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name *still connascence. of value, but locality close
  23. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Examples Types of connascence: •

    Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name Types of connascence: • Connascence of Identity • Connascence of Value • Connascence of Timing • Connascence of Execution Order • Connascence of Position • Connascence of Algorithm • Connascence of Meaning • Connascence of Type • Connascence of Name
  24. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Usage • Gives me a

    way to evaluate and prioritize code review/refactor (now I don’t do fixes that are easiest but the most risky) • New tool to communicate (good reviews aren’t based on personal taste but on objective metric) • Gives new developers a framework/compass/guidance for writing good, clean, and maintainable code
  25. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Usage • Gives me a

    way to evaluate and prioritize code review/refactor (now I don’t do fixes that are easiest but the most risky) • New tool to communicate (good reviews aren’t based on personal taste but on objective metric) • Gives new developers a framework/compass/guidance for writing good, clean, and maintainable code Propose!
  26. @PandaScriptCom @thadeuszlay linkedin.com/in/trung-thanh-le/ PandaScript.com [email protected] Sources • “What every Software

    Developer should know about Object-Oriented Programming” by Meilir Page-Jones • ETE 2012 - Jim Weirich - Connascence Examined: https://www.youtube.com/watch?v=NLT7Qcn_PmI • Codemania 2015: Josh Robb - Connascence & Coupling: https://www.youtube.com/watch?v=Ip2o4vbAK3s