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

Surrender The Illusion of Control

Steve Tooke
September 07, 2015

Surrender The Illusion of Control

SwanseaCon 2015

Steve Tooke

September 07, 2015
Tweet

More Decks by Steve Tooke

Other Decks in Programming

Transcript

  1. XP

  2. TDD

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

    head that you really understand the problem. 1 Paul Graham
  4. Connascence1 1. The birth of two or more things at

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

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

    8. Connascence of Value 9. Connascence of Identity
  8. 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
  9. 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--")); } }
  10. 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"; } }
  11. 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"; } }
  12. 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--")); } }
  13. 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"; } }
  14. 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"; } }
  15. 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); } }
  16. 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); } }
  17. 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 + ""; } }
  18. 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); } }
  19. 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
  20. 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
  21. 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
  22. 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
  23. DRY

  24. 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/