Steve Tooke
September 07, 2015
200

# Surrender The Illusion of Control

SwanseaCon 2015

#### Steve Tooke

September 07, 2015

## Transcript

6. None
7. None
8. None
9. None
10. None

12. None

17. None
18. None
19. None
20. None
21. None

23. ### So it's only when you have your code in your

head that you really understand the problem. 1 Paul Graham
24. None

26. None
27. None
28. ### Connascence1 1. The birth of two or more things at

the same time. 2. The act of growing together 1 From wiktionary
29. ### 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
30. ### Static Connascence 1. Connascence of Name 2. Connascence of Type

3. Connascence of Meaning 4. Connascence of Algorithm 5. Connascence of Position
31. ### Dynamic Connascence 6. Connascence of Execution 7. Connascence of Timing

8. Connascence of Value 9. Connascence of Identity

33. ### Connascence of Name class CardTest < Minitest::Test def test_high_card_beats_low_card high_card

= Card.new("10", "♥") low_card = Card.new("2", "♣") assert high_card.beats?(low_card) end end class Card < Struct.new(:rank, :suit) def beats?(other_card) true end end

35. ### Connascence of Type public class DiamondTest { @Test public void

first_row_of_A_diamond() { String diamond = Diamond.upTo("A"); assertThat(diamond, is("A")); } @Test public void first_row_of_B_diamond() { String diamond = Diamond.upTo("B"); assertThat(diamond, is("-A-")); } @Test public void first_row_of_C_diamond() { String diamond = Diamond.upTo("C"); assertThat(diamond, is("--A--")); } }
36. ### Connascence of Type public class Diamond { public static String

upTo(String letter) { if ("C".equals(letter)) { return "--" + "A" + "--"; } if ("B".equals(letter)) { return "-" + "A" + "-"; } return "A"; } }
37. ### public class DiamondTest { @Test public void first_row_of_A_diamond() { String

diamond = Diamond.upTo("A"); assertThat(diamond, is("A")); } // ... } public class Diamond { public static String upTo(String letter) { if ("C".equals(letter)) { return "--" + "A" + "--"; } if ("B".equals(letter)) { return "-" + "A" + "-"; } return "A"; } }
38. ### Connascence of Type public class DiamondTest { @Test public void

first_row_of_A_diamond() { String diamond = Diamond.upTo('A'); assertThat(diamond, is("A")); } @Test public void first_row_of_B_diamond() { String diamond = Diamond.upTo('B'); assertThat(diamond, is("-A-")); } @Test public void first_row_of_C_diamond() { String diamond = Diamond.upTo('C'); assertThat(diamond, is("--A--")); } }
39. ### Connascence of Type public class Diamond { public static String

upTo(char letter) { if ('C'.equals(letter)) { return "--" + "A" + "--"; } if ('B'.equals(letter)) { return "-" + "A" + "-"; } return "A"; } }

41. ### Connascence of Meaning public class Diamond { public static String

upTo(char letter) { if ('C'.equals(letter)) { return "--" + "A" + "--"; } if ('B'.equals(letter)) { return "-" + "A" + "-"; } return "A"; } }
42. ### Connascence of Name > Connascence of Meaning public class Diamond

{ public static final char START_LETTER = 'A'; public static String upTo(char letter) { if ('C'.equals(letter)) { return "--" + START_LETTER + "--"; } if ('B'.equals(letter)) { return "-" + START_LETTER + "-"; } return valueof(START_LETTER); } }

44. ### Connascence of Algorithm public class Diamond { public static final

char START_LETTER = 'A'; public static String upTo(char letter) { if ('C'.equals(letter)) { return "--" + START_LETTER + "--"; } if ('B'.equals(letter)) { return "-" + START_LETTER + "-"; } return valueof(START_LETTER); } }
45. ### Connascence of Algorithm public class Diamond { public static final

char START_LETTER = 'A'; public static String upTo(char letter) { if ('C'.equals(letter)) { return "--" + START_LETTER + "--"; } if ('B'.equals(letter)) { return "-" + START_LETTER + "-"; } return "" + START_LETTER + ""; } }
46. ### Connascence of Name > Connascence of Algorithm public class Diamond

{ public static final char START_LETTER = 'A'; public static String upTo(char letter) { return padding(letter) + START_LETTER + padding(letter); } private static string padding(char letter) { int paddingSize = letter - START_LETTER; return StringUtils.repeat("-", paddingSize); } }

48. ### Connascence of Position class CardTest < Minitest::Test def test_high_card_beats_low_card high_card

= Card.new("10", "♥") low_card = Card.new("2", "♣") assert high_card.beats?(low_card) end end class Card < Struct.new(:rank, :suit) end
49. ### Connascence of Position class CardTest < Minitest::Test def test_high_card_beats_low_card high_card

= Card.new("10", "♥") low_card = Card.new("2", "♣") assert high_card.beats?(low_card) end end class Card < Struct.new(:suit, :rank) end
50. ### Connascence of Position class CardTest < Minitest::Test def test_high_card_beats_low_card high_card

= Card.new("♥", "10") low_card = Card.new("♣", "2") assert high_card.beats?(low_card) end end class Card < Struct.new(:suit, :rank) end
51. ### Connascence of Name > Position class Card def initialize(rank:, suit:)

@rank = rank @suit = suit end # ... end
52. ### Connascence of Name > Position class CardTest < Minitest::Test def

test_high_card_beats_low_card high_card = Card.new(rank: "10", suit: "♥") low_card = Card.new(suit: "♣", rank: "2") assert high_card.beats?(low_card) end end

54. None
55. None
56. ### Locality class AvailableJobs def jobs [[customer, description]] end def assign_to(worker)

jobs.each do |customer, description| # ... end end end
57. ### Locality class AvailableJobs def jobs [[description, customer]] end def assign_to(worker)

jobs.each do |customer, description| # ... end end end

59. ### Locality class InvoiceClerk def generate_job_invoices(jobs) jobs.each do |customer, description| #

... end end end

61. ### Degree class CompletedJobs def jobs [[customer, reference, description, start_time, finish_time,

rate]] end end
62. ### Degree class InvoiceClerk def generate_job_invoices(jobs) jobs.each do |customer, reference, description,

start_time, finish_time, rate| # ... end end end

end

end end end

connascence
68. ### When you have a high degree of connascence convert to

a weaker form of connascence

77. None

80. ### Photos good_design_1.jpg: https://www.flickr.com/photos/opalsson/ bad_design.jpg: https://www.reddit.com/r/todayilearned/comments/2dvvja/til_that_in_order_to_preserve_the_states_natural/ greenfield.jpg: https://www.flickr.com/photos/ks_marks/ stuckInTheMud.jpg: https://www.flickr.com/photos/puuikibeach/ unicorn.jpg:

https://www.flickr.com/photos/wayfinder/ jimWeirich.jpg: https://www.flickr.com/photos/fraserspeirs/ celebrate.jpg: https://www.flickr.com/photos/clement127/ modular.jpg: https://www.flickr.com/photos/rahul3/ connected.jpg: https://www.flickr.com/photos/bernd_thaller/ reduceCost.jpg: https://www.flickr.com/photos/68751915@N05/ change.jpg: https://www.flickr.com/photos/petereed/