Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
© XPSurgery.com 2016 @kevinrutherford
Love and Death
“To love is to suffer. To avoid suffering
one must not love. But then...
© XPSurgery.com 2016 @kevinrutherford
@kevinrutherford @xpsurgery
http://silkandspinach.net http://xpsurgery.com
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Extreme Normal Form:
1. Passes all tests
2. Expresses intent
3. No duplication
4. No...
© XPSurgery.com 2016 @kevinrutherford
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphism
Lazy Class
Temporary Field...
© XPSurgery.com 2016 @kevinrutherford
S ingle responsibility principle
O pen-closed principle
L iskov substitution princip...
© XPSurgery.com 2016 @kevinrutherford
Principles of package cohesion
Reuse-release equivalence principle (REP)
Common-reus...
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
“This is Mrs Bencours,
one of my patients.
She thinks she's a sheep.”
Everything you...
© XPSurgery.com 2016 @kevinrutherford
Comparing Techniques by Means of Encapsulation
and Connascence,
Communications of th...
© XPSurgery.com 2016 @kevinrutherford
1996
Meilir
Page-Jones
© XPSurgery.com 2016 @kevinrutherford
1999
Meilir
Page-Jones
© XPSurgery.com 2016 @kevinrutherford
Connascence between two software elements
A and B means either:
1) some change to A ...
© XPSurgery.com 2016 @kevinrutherford
Connascence between two software elements
A and B means either:
1) some change to A ...
© XPSurgery.com 2016 @kevinrutherford
Meilir
Page-Jones
“I'll go so far as to say
that connascence [is]
at the heart of mo...
© XPSurgery.com 2016 @kevinrutherford
2005-9
Grand Unified Theory
of Software Design
Jim
Weirich
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
Degree
Type
Reach
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Name
int i = 9;
int j = Math.sqrt(i);
N
N N
N
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
A
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
hash(...)
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Algorithm
get(...) put(...)
hash(...)
A
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Position
printf(“%d %sn”, time.now(), request.path);
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Position
printf(“%d %sn”, time.now(), request.path);
P
[static]
© XPSurgery.com 2016 @kevinrutherford
Connascence of Convention
int basePrice = priceFor(sku); //  999 pence (== £9.99)
d...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Convention
int basePrice = priceFor(sku); //  999 pence (== £9.99)
d...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Type
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Type
int basePrice = priceFor(sku); //  999 pence (== £9.99)
decimal...
© XPSurgery.com 2016 @kevinrutherford
Static connascence:
Name Convention
Algorithm Type
Position (Difference)
© XPSurgery.com 2016 @kevinrutherford
string[] board = new string[12];
     :
     :
if (position[currentPlayer] > 11)
  i...
© XPSurgery.com 2016 @kevinrutherford
string[] board = new string[12];
     :
     :
if (position[currentPlayer] > 11)
  i...
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydoma...
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydoma...
© XPSurgery.com 2016 @kevinrutherford
email = Email.new()
email.setRecipient("foo@example.com")
email.setSender("me@mydoma...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Identity
[dynamic]
fetch(`http://localhost:17174/salesmen/${salesmanI...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Identity
[dynamic]
fetch(`http://localhost:17174/salesmen/${salesmanI...
© XPSurgery.com 2016 @kevinrutherford
Connascence of Timing
[dynamic]
xrayMachine.on()
Thread.sleep(20)
xrayMachine.off()
© XPSurgery.com 2016 @kevinrutherford
Connascence of Timing
[dynamic]
xrayMachine.on()
Thread.sleep(20)
xrayMachine.off()
T
© XPSurgery.com 2016 @kevinrutherford
Dynamic connascence:
Value Timing
Execution (Difference)
Identity
© XPSurgery.com 2016 @kevinrutherford
Degree
Type
Reach
© XPSurgery.com 2016 @kevinrutherford
50
50
V = 2
E = 1
© XPSurgery.com 2016 @kevinrutherford
50
50
50
V = 3
E = 3
© XPSurgery.com 2016 @kevinrutherford
50
50
50
50
V = 4
E = 6
© XPSurgery.com 2016 @kevinrutherford
V = 5
E = 10
50
50
50
50
50
© XPSurgery.com 2016 @kevinrutherford
Type
Degree
Reach
© XPSurgery.com 2016 @kevinrutherford
expression ↔ expression 0
function ↔ function 1
object ↔ object 2
aggregate ↔ aggreg...
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation bound...
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation bound...
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
By breaking the system into
encapsulated elements
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Ca,b
= f(type, level, degree)
?
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
© XPSurgery.com 2016 @kevinrutherford
Primitive Obsession
Feature Envy
Sim
ulated
Polym
orphism
Lazy Class
Temporary Field...
© XPSurgery.com 2016 @kevinrutherford
“I'll go so far as to say
that connascence [is]
at the heart of modern
software-engi...
© XPSurgery.com 2016 @kevinrutherford
Degree
Reach
Type
© XPSurgery.com 2016 @kevinrutherford
1. Minimize overall connascence
2. Minimize connascence crossing
encapsulation bound...
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
Ca,b
= f(type, level, degree)
© XPSurgery.com 2016 @kevinrutherford
1. Break the monolith you have into
meaningful encapsulation units
2. Remove the “wo...
© XPSurgery.com 2016 @kevinrutherford
© XPSurgery.com 2016 @kevinrutherford
?
@kevinrutherford
@xpsurgery
http://silkandspinach.net/tag/connascence
http://xpsur...
Upcoming SlideShare
Loading in …5
×

Love and death

145 views

Published on

Slides from a talk about connascence, given at XProLo in June 2016 and NWRUG in July 2016

Published in: Software
  • Be the first to comment

  • Be the first to like this

Love and death

  1. 1. © XPSurgery.com 2016 @kevinrutherford Love and Death “To love is to suffer. To avoid suffering one must not love. But then one suffers from not loving. Therefore, to love is to suffer; not to love is to suffer; to suffer is to suffer. To be happy is to love. To be happy, then, is to suffer, but suffering makes one unhappy. Therefore, to be unhappy, one must love or love to suffer or suffer from too much happiness. I hope you're getting this down.” Love and Death, Woody Allen, 1975
  2. 2. © XPSurgery.com 2016 @kevinrutherford @kevinrutherford @xpsurgery http://silkandspinach.net http://xpsurgery.com
  3. 3. © XPSurgery.com 2016 @kevinrutherford
  4. 4. © XPSurgery.com 2016 @kevinrutherford
  5. 5. © XPSurgery.com 2016 @kevinrutherford ?
  6. 6. © XPSurgery.com 2016 @kevinrutherford
  7. 7. © XPSurgery.com 2016 @kevinrutherford
  8. 8. © XPSurgery.com 2016 @kevinrutherford Extreme Normal Form: 1. Passes all tests 2. Expresses intent 3. No duplication 4. No extra stuff
  9. 9. © XPSurgery.com 2016 @kevinrutherford Primitive Obsession Feature Envy Sim ulated Polym orphism Lazy Class Temporary Field Inappropriate Intim acy ShotgunSurgery Data Clump Long M ethod Large Class ??? ??? ??? ??? ??? ??? ??? RefusedBequest
  10. 10. © XPSurgery.com 2016 @kevinrutherford S ingle responsibility principle O pen-closed principle L iskov substitution principle I nterface segregation principle D ependency inversion principle
  11. 11. © XPSurgery.com 2016 @kevinrutherford Principles of package cohesion Reuse-release equivalence principle (REP) Common-reuse principle (CRP) Common-closure principle (CCP) Principles of package coupling Acyclic dependencies principle (ADP) Stable-dependencies principle (SDP) Stable-abstractions principle (SAP)
  12. 12. © XPSurgery.com 2016 @kevinrutherford
  13. 13. © XPSurgery.com 2016 @kevinrutherford
  14. 14. © XPSurgery.com 2016 @kevinrutherford “This is Mrs Bencours, one of my patients. She thinks she's a sheep.” Everything you always wanted to know about sex but were afraid to ask, Woody Allen, 1975 coupling
  15. 15. © XPSurgery.com 2016 @kevinrutherford Comparing Techniques by Means of Encapsulation and Connascence, Communications of the ACM Vol. 35, No. 9, Sept. 1992 pp. 147-151 Meilir Page-Jones
  16. 16. © XPSurgery.com 2016 @kevinrutherford 1996 Meilir Page-Jones
  17. 17. © XPSurgery.com 2016 @kevinrutherford 1999 Meilir Page-Jones
  18. 18. © XPSurgery.com 2016 @kevinrutherford Connascence between two software elements A and B means either: 1) some change to A would require B to be changed, or 2) some change would require both A and B to be changed together in order to preserve overall correctness.
  19. 19. © XPSurgery.com 2016 @kevinrutherford Connascence between two software elements A and B means either: 1) some change to A would require B to be changed, (or at least carefully checked), or 2) some change would require both A and B to be changed together in order to preserve overall correctness.
  20. 20. © XPSurgery.com 2016 @kevinrutherford Meilir Page-Jones “I'll go so far as to say that connascence [is] at the heart of modern software-engineering constructs.”
  21. 21. © XPSurgery.com 2016 @kevinrutherford 2005-9 Grand Unified Theory of Software Design Jim Weirich
  22. 22. © XPSurgery.com 2016 @kevinrutherford
  23. 23. © XPSurgery.com 2016 @kevinrutherford
  24. 24. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  25. 25. © XPSurgery.com 2016 @kevinrutherford Degree Type Reach
  26. 26. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  27. 27. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  28. 28. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  29. 29. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); [static]
  30. 30. © XPSurgery.com 2016 @kevinrutherford Connascence of Name int i = 9; int j = Math.sqrt(i); N N N N [static]
  31. 31. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) [static]
  32. 32. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) A [static]
  33. 33. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) hash(...) [static]
  34. 34. © XPSurgery.com 2016 @kevinrutherford Connascence of Algorithm get(...) put(...) hash(...) A [static]
  35. 35. © XPSurgery.com 2016 @kevinrutherford Connascence of Position printf(“%d %sn”, time.now(), request.path); [static]
  36. 36. © XPSurgery.com 2016 @kevinrutherford Connascence of Position printf(“%d %sn”, time.now(), request.path); P [static]
  37. 37. © XPSurgery.com 2016 @kevinrutherford Connascence of Convention int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; [static]
  38. 38. © XPSurgery.com 2016 @kevinrutherford Connascence of Convention int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; C [static]
  39. 39. © XPSurgery.com 2016 @kevinrutherford Connascence of Type int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; [static]
  40. 40. © XPSurgery.com 2016 @kevinrutherford Connascence of Type int basePrice = priceFor(sku); //  999 pence (== £9.99) decimal salesTax = calcTax(basePrice); return basePrice + salesTax; T [static]
  41. 41. © XPSurgery.com 2016 @kevinrutherford Static connascence: Name Convention Algorithm Type Position (Difference)
  42. 42. © XPSurgery.com 2016 @kevinrutherford string[] board = new string[12];      :      : if (position[currentPlayer] > 11)   index = 0; Connascence of Value [dynamic]
  43. 43. © XPSurgery.com 2016 @kevinrutherford string[] board = new string[12];      :      : if (position[currentPlayer] > 11)   index = 0; Connascence of Value [dynamic] V
  44. 44. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic]
  45. 45. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic] E
  46. 46. © XPSurgery.com 2016 @kevinrutherford email = Email.new() email.setRecipient("foo@example.com") email.setSender("me@mydomain.com") email.setSubject("Hello World") email.send() Connascence of Execution [dynamic] E E
  47. 47. © XPSurgery.com 2016 @kevinrutherford Connascence of Identity [dynamic] fetch(`http://localhost:17174/salesmen/${salesmanId}`, {   method: 'put',   body: JSON.stringify({     salesmanId: salesmanId,     orderId: orderId,     commission: commission   }) })
  48. 48. © XPSurgery.com 2016 @kevinrutherford Connascence of Identity [dynamic] fetch(`http://localhost:17174/salesmen/${salesmanId}`, {   method: 'put',   body: JSON.stringify({     salesmanId: salesmanId,     orderId: orderId,     commission: commission   }) }) I
  49. 49. © XPSurgery.com 2016 @kevinrutherford Connascence of Timing [dynamic] xrayMachine.on() Thread.sleep(20) xrayMachine.off()
  50. 50. © XPSurgery.com 2016 @kevinrutherford Connascence of Timing [dynamic] xrayMachine.on() Thread.sleep(20) xrayMachine.off() T
  51. 51. © XPSurgery.com 2016 @kevinrutherford Dynamic connascence: Value Timing Execution (Difference) Identity
  52. 52. © XPSurgery.com 2016 @kevinrutherford Degree Type Reach
  53. 53. © XPSurgery.com 2016 @kevinrutherford 50 50 V = 2 E = 1
  54. 54. © XPSurgery.com 2016 @kevinrutherford 50 50 50 V = 3 E = 3
  55. 55. © XPSurgery.com 2016 @kevinrutherford 50 50 50 50 V = 4 E = 6
  56. 56. © XPSurgery.com 2016 @kevinrutherford V = 5 E = 10 50 50 50 50 50
  57. 57. © XPSurgery.com 2016 @kevinrutherford Type Degree Reach
  58. 58. © XPSurgery.com 2016 @kevinrutherford expression ↔ expression 0 function ↔ function 1 object ↔ object 2 aggregate ↔ aggregate 3 process ↔ process 4
  59. 59. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  60. 60. © XPSurgery.com 2016 @kevinrutherford
  61. 61. © XPSurgery.com 2016 @kevinrutherford
  62. 62. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  63. 63. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  64. 64. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence By breaking the system into encapsulated elements
  65. 65. © XPSurgery.com 2016 @kevinrutherford
  66. 66. © XPSurgery.com 2016 @kevinrutherford
  67. 67. © XPSurgery.com 2016 @kevinrutherford
  68. 68. © XPSurgery.com 2016 @kevinrutherford
  69. 69. © XPSurgery.com 2016 @kevinrutherford Ca,b = f(type, level, degree) ?
  70. 70. © XPSurgery.com 2016 @kevinrutherford
  71. 71. © XPSurgery.com 2016 @kevinrutherford
  72. 72. © XPSurgery.com 2016 @kevinrutherford ?
  73. 73. © XPSurgery.com 2016 @kevinrutherford Primitive Obsession Feature Envy Sim ulated Polym orphism Lazy Class Temporary Field Inappropriate Intim acy ShotgunSurgery Data Clump Long M ethod Large Class ??? ??? ??? ??? ??? ??? ??? RefusedBequest
  74. 74. © XPSurgery.com 2016 @kevinrutherford “I'll go so far as to say that connascence [is] at the heart of modern software-engineering constructs.”
  75. 75. © XPSurgery.com 2016 @kevinrutherford Degree Reach Type
  76. 76. © XPSurgery.com 2016 @kevinrutherford 1. Minimize overall connascence 2. Minimize connascence crossing encapsulation boundaries By breaking the system into encapsulated elements By maximising the connascence within encapsulation boundaries
  77. 77. © XPSurgery.com 2016 @kevinrutherford
  78. 78. © XPSurgery.com 2016 @kevinrutherford Ca,b = f(type, level, degree)
  79. 79. © XPSurgery.com 2016 @kevinrutherford 1. Break the monolith you have into meaningful encapsulation units 2. Remove the “worst” connascence among the encapsulation units 3. Find which encapsulation units have the “most” internal connascence 4. Recurse into each, returning to the top level after each one
  80. 80. © XPSurgery.com 2016 @kevinrutherford
  81. 81. © XPSurgery.com 2016 @kevinrutherford ? @kevinrutherford @xpsurgery http://silkandspinach.net/tag/connascence http://xpsurgery.com

×