$30 off During Our Annual Pro Sale. View Details »

Overkill

 Overkill

When is it okay to build an orbital laser to destroy an ant-hill?

Many cry "overkill" when design principles are applied to trivial problems. And for good reason: in the context of work, excessive embellishment gets us into trouble. Complexity costs us time and money.

This talk explores how stepping outside of the realm of work and applying outrageous engineering practices to toy problems can deepen our understanding of the trade-offs that we make. Comically simple problems provide the perfect ground for developing actionable heuristics which can be applied to those monstrous complexities that we face in the real world.

Katrina Owen

April 03, 2014
Tweet

More Decks by Katrina Owen

Other Decks in Programming

Transcript

  1. Katrina Owen
    @kytrinyx
    http://exercism.io
    Overkill

    View Slide

  2. View Slide

  3. 1
    2
    ...
    3563
    3564
    class Thing
    #...
    end
    /app/models/thing.rb

    View Slide


  4. View Slide

  5. Oh. Shit.

    View Slide

  6. 1
    2
    ...
    3563
    3564
    class Thing
    #...
    end
    /app/models/thing.rb

    View Slide

  7. 1
    2
    ...
    3532
    3533
    class Thing
    #...
    end
    /app/models/thing.rb

    View Slide

  8. something
    different

    View Slide

  9. README

    View Slide

  10. README
    Bob is a lackadaisical teenager. In
    conversation, his responses are very
    limited.

    View Slide

  11. README

    View Slide

  12. README
    Bob answers 'Sure.' if you ask him a
    question.
    He answers 'Whoa, chill out!' if you yell at
    him.
    He says 'Fine. Be that way!' if you address
    him without actually saying anything.
    He answers 'Whatever.' to anything else.

    View Slide

  13. test suite

    View Slide

  14. test suite

    View Slide

  15. test suite
    "Does this cryogenic chamber
    make me look fat?"
    Sure.

    View Slide

  16. test suite

    View Slide

  17. test suite
    "WATCH OUT!"
    Whoa, chill out!

    View Slide

  18. test suite

    View Slide

  19. test suite
    ""
    Fine. Be that way!

    View Slide

  20. test suite

    View Slide

  21. test suite
    "Tom-ay-to, tom-aaaah-to."
    Whatever.

    View Slide

  22. edge cases
    test suite

    View Slide

  23. test suite

    View Slide

  24. test suite
    "Ending with ? means a
    question."
    Whatever.

    View Slide

  25. test suite

    View Slide

  26. test suite
    "I HATE YOU"
    Whoa, chill out!

    View Slide

  27. test suite

    View Slide

  28. test suite
    "Let's go make out behind
    the gym!"
    Whatever.

    View Slide

  29. test suite

    View Slide

  30. test suite
    "WHAT THE HELL WERE YOU
    THINKING?"
    Whoa, chill out!

    View Slide

  31. test suite

    View Slide

  32. test suite
    "1, 2, 3"
    Whatever.

    View Slide

  33. test suite

    View Slide

  34. test suite
    "1, 2, 3 GO!"
    Whoa, chill out!

    View Slide

  35. test suite

    View Slide

  36. test suite
    "4?"
    Sure.

    View Slide

  37. test suite

    View Slide

  38. test suite
    "ZOMG THE %^*@#$(*^ ZOMBIES
    ARE COMING!!11!!1!"
    Whoa, chill out!

    View Slide

  39. code

    View Slide

  40. code
    24 iterations

    View Slide

  41. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    Iteration #1

    View Slide

  42. return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  43. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  44. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  45. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  46. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  47. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end
    Iteration #1

    View Slide

  48. Iteration #1
    class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end

    View Slide

  49. class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end
    Iteration #1
    class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input =="1, 2, 3"
    return "Whatever."
    elsif input=="4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return"Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input== "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input==""
    return"Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input==" "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return"Whatever."
    end
    end
    end

    View Slide

  50. take-away #1

    View Slide

  51. take-away #1
    whitespace is meaningful

    View Slide

  52. Iteration #2
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."

    View Slide

  53. Iteration #2
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end

    View Slide

  54. Iteration #2
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end

    View Slide

  55. Iteration #2
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end

    View Slide

  56. Iteration #2
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end

    View Slide

  57. Iteration #2
    class Bob
    def hey(input)
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end
    end
    end
    class Bob
    def hey(input)
    if input == "Tom-ay-to, tom-aaaah-to."
    return "Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input == "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    elsif input == "WHAT THE HELL WERE YOU THINKING?"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3 GO!"
    return "Whoa, chill out!"
    elsif input == "1, 2, 3"
    return "Whatever."
    elsif input == "4?"
    return "Sure."
    elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    return "Whoa, chill out!"
    elsif input == "I HATE YOU"
    return "Whoa, chill out!"
    elsif input == "Ending with ? means a question."
    return "Whatever."
    elsif input == "Wait! Hang on. Are you going to be OK?"
    return "Sure."
    elsif input == ""
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == " "
    return "Fine. Be that way!"
    elsif input == "Does this cryogenic chamber make me look fat?\nno"
    return "Whatever."
    end
    end
    end

    View Slide

  58. take-away #2

    View Slide

  59. take-away #2
    minimize boilerplate

    View Slide

  60. Iteration #3
    class Bob
    def hey(input)
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"

    View Slide

  61. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  62. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  63. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  64. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  65. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  66. Iteration #3
    case input
    when "Tom-ay-to, tom-aaaah-to."
    "Whatever."
    when "WATCH OUT!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?"
    "Sure."
    when "You are, what, like 15?"
    "Sure."
    when "Let's go make out behind the gym!"
    "Whatever."
    when "It's OK if you don't want to go to the DMV."
    "Whatever."
    when "WHAT THE HELL WERE YOU THINKING?"
    "Whoa, chill out!"
    when "1, 2, 3 GO!"
    "Whoa, chill out!"
    when "1, 2, 3"
    "Whatever."
    when "4?"
    "Sure."
    when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?\nno"
    "Whatever."
    when "I HATE YOU"
    "Whoa, chill out!"
    when "Ending with ? means a question."
    "Whatever."
    when "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when ""
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    when " "
    "Fine. Be that way!"
    end

    View Slide

  67. Iteration #3
    class Bob
    def hey(input)
    case input
    when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym!
    "Whatever."
    when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO!
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?", "You are, wha
    "Sure."
    when "", " ", " "
    "Fine. Be that way!"
    end
    end
    end

    View Slide

  68. Iteration #3
    ic chamber make me look fat?\nno", "Ending with ? means a question."

    View Slide

  69. there
    I fixed it!

    View Slide

  70. take-away #3

    View Slide

  71. take-away #3
    don’t repeat yourself (DRY)

    View Slide

  72. Iteration #4
    class Bob
    def hey(input)
    case input
    when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym!
    "Whatever."
    when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO!
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?", "You are, wha
    "Sure."
    when "", " ", " "
    "Fine. Be that way!"
    end
    end
    end

    View Slide

  73. Iteration #4
    class Bob
    def hey(input)
    case input
    when "Tom-ay-to, tom-aaaah-to.",
    "Let's go make out behind the gym!",
    "It's OK if you don't want to go to the DMV.",
    "1, 2, 3",
    "Does this cryogenic chamber make me look fat?\nno",
    "Ending with ? means a question."
    "Whatever."
    when "WATCH OUT!",
    "WHAT THE HELL WERE YOU THINKING?",
    "1, 2, 3 GO!",
    "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
    "I HATE YOU"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?",
    "You are, what, like 15?",
    "4?",
    "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when "",
    " ",
    " "
    "Fine. Be that way!"
    end
    end
    end

    View Slide

  74. Iteration #4
    "Sure."
    when "",
    " ",
    " "
    "Fine. Be that way!"
    end
    end
    end

    View Slide

  75. Iteration #4
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?",
    "You are, what, like 15?",
    "4?",
    "Wait! Hang on. Are you going to be OK?"
    "Sure."
    when "",

    View Slide

  76. Iteration #4
    "Whatever."
    when "WATCH OUT!",
    "WHAT THE HELL WERE YOU THINKING?",
    "1, 2, 3 GO!",
    "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
    "I HATE YOU"
    "Whoa, chill out!"
    when "Does this cryogenic chamber make me look fat?",

    View Slide

  77. Iteration #4
    case input
    when "Tom-ay-to, tom-aaaah-to.",
    "Let's go make out behind the gym!",
    "It's OK if you don't want to go to the DMV.",
    "1, 2, 3",
    "Does this cryogenic chamber make me look fat?\nno",
    "Ending with ? means a question."
    "Whatever."
    when "WATCH OUT!",

    View Slide

  78. Iteration #5
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/
    return "Sure." if input.split("").last == "?"
    return "Fine. Be that way!" if input.strip == ""
    "Whatever."
    end
    end

    View Slide

  79. take-away #4

    View Slide

  80. take-away #4
    find the abstraction

    View Slide

  81. Iteration #5
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/
    return "Sure." if input.split("").last == "?"
    return "Fine. Be that way!" if input.strip == ""
    "Whatever."
    end
    end

    View Slide

  82. Iteration #5
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/
    return "Sure." if input.split("").last == "?"
    return "Fine. Be that way!" if input.strip == ""
    "Whatever."
    end
    end

    View Slide

  83. Iteration #5
    input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/

    View Slide

  84. input == input.upcase
    Iteration #5

    View Slide

  85. input == input.upcase and input != input.downcase
    Iteration #5

    View Slide

  86. Iteration #5
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase and input != input.downcase
    return "Sure." if input.split("").last == "?"
    return "Fine. Be that way!" if input.strip == ""
    "Whatever."
    end
    end

    View Slide

  87. Iteration #5
    input.split("").last == "?"

    View Slide

  88. Iteration #5
    input.end_with?("?")

    View Slide

  89. Iteration #5
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase and input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip == ""
    "Whatever."
    end
    end

    View Slide

  90. Iteration #5
    input.strip == ""

    View Slide

  91. input.strip.empty?
    Iteration #5

    View Slide

  92. take-away #5

    View Slide

  93. take-away #5
    seek fluency

    View Slide

  94. Iteration #6
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase and input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip.empty?
    "Whatever."
    end
    end

    View Slide

  95. input == input.upcase and input != input.downcase
    So expressive!

    View Slide

  96. and
    control flow operator

    View Slide

  97. &&
    boolean operator

    View Slide

  98. boolean vs control flow
    hungry? && thirsty?

    View Slide

  99. rich? && famous?
    boolean vs control flow

    View Slide

  100. sing and dance
    boolean vs control flow

    View Slide

  101. rise and shine
    boolean vs control flow

    View Slide

  102. boolean vs control flow
    if hungry? && thirsty?
    eat and drink and be_merry!
    end

    View Slide

  103. Iteration #6
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase and input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip.empty?
    "Whatever."
    end
    end

    View Slide

  104. Iteration #6
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase && input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip.empty?
    "Whatever."
    end
    end

    View Slide

  105. take-away #6

    View Slide

  106. take-away #6
    familiar isn’t always
    correct

    View Slide

  107. Iteration #7
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase && input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip.empty?
    "Whatever."
    end
    end

    View Slide

  108. Iteration #7
    class Bob
    def hey(input)
    return "Whoa, chill out!" if input == input.upcase && input != input.downcase
    return "Sure." if input.end_with?("?")
    return "Fine. Be that way!" if input.strip.empty?
    "Whatever."
    end
    end

    View Slide

  109. Iteration #7
    class Bob
    def hey(input)
    case
    when input == input.upcase && input != input.downcase
    "Whoa, chill out!"
    when input.end_with?("?")
    "Sure."
    when input.strip.empty?
    "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end

    View Slide

  110. take-away #7

    View Slide

  111. take-away #7
    shorter is better, unless it
    means something else

    View Slide

  112. Iteration #8
    class Bob
    def hey(input)
    case
    when input == input.upcase && input != input.downcase
    "Whoa, chill out!"
    when input.end_with?("?")
    "Sure."
    when input.strip.empty?
    "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end

    View Slide

  113. Iteration #8
    class Bob
    def hey(input)
    @input = input
    case
    when all_caps? then "Whoa, chill out!"
    when question? then "Sure."
    when empty? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def empty?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def all_caps?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  114. a what-now?
    all_caps?
    question?
    empty?

    View Slide

  115. a what-now?
    all_caps?
    question?
    empty?
    ➔ shout?

    View Slide

  116. a what-now?
    all_caps?
    question?
    empty?
    ➔ shout?
    ➔ silence?

    View Slide

  117. a what-now?
    shout?
    question?
    silence?

    View Slide

  118. take-away #8

    View Slide

  119. take-away #8
    hide the fiddly details

    View Slide

  120. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  121. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  122. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  123. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  124. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  125. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  126. Iteration #9
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  127. take-away #9

    View Slide

  128. take-away #9
    make the public API coherent

    View Slide

  129. Iteration #10
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  130. Iteration #10
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?
    @input.strip.empty?
    end
    def question?
    @input.end_with?("?")
    end
    def shout?
    @input == @input.upcase && @input != @input.downcase
    end
    end

    View Slide

  131. Iteration #10
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    attr_reader :input
    def silence?
    input.strip.empty?
    end
    def question?
    input.end_with?("?")
    end
    def shout?
    input == input.upcase && input != input.downcase
    end
    end

    View Slide

  132. take-away #10

    View Slide

  133. take-away #10
    send a message

    View Slide

  134. Iteration #11
    class Bob
    def hey(input)
    @input = input
    case
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    attr_reader :input
    def silence?
    input.strip.empty?
    end
    def question?
    input.end_with?("?")
    end
    def shout?
    input == input.upcase && input != input.downcase
    end
    end

    View Slide

  135. confusion ensues
    B A

    View Slide

  136. confusion ensues
    B A
    "ARE YOU CRAZY?"

    View Slide

  137. "ARE YOU CRAZY?"
    @input
    confusion ensues
    B A
    "ARE YOU CRAZY?"

    View Slide

  138. "ARE YOU CRAZY?"
    @input
    confusion ensues
    B A
    "ARE YOU CRAZY?"
    C
    "You’re late."

    View Slide

  139. @input
    "You’re late."
    confusion ensues
    B A
    "ARE YOU CRAZY?"
    C
    "You’re late."

    View Slide

  140. confusion ensues
    B A

    View Slide

  141. @input
    "You’re late."
    confusion ensues
    B A

    View Slide

  142. @input
    "You’re late."
    confusion ensues
    "Whatever."
    B A

    View Slide

  143. private
    attr_reader :input
    def silence?
    input.strip.empty?
    end
    ...
    Iteration #11

    View Slide

  144. private
    attr_reader :input
    def silence?
    input.strip.empty?
    end
    ...
    Iteration #11
    private
    def silence?
    ->(s) { s.strip.empty? }
    end
    ...

    View Slide

  145. take-away #11

    View Slide

  146. take-away #11
    fleeting state doesn’t
    belong in instance variables

    View Slide

  147. Iteration #12
    class Bob
    def hey(input)
    case input
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?
    ->(s) { s.strip.empty? }
    end
    def question?
    ->(s) { s.end_with?("?") }
    end
    def shout?
    ->(s) { s == s.upcase && s != s.downcase }
    end
    end

    View Slide

  148. special case
    case age
    when ->(i) { i < 13 } then "kiddo"
    when ->(i) { i % 25 == 0 } then "quarter"
    when ->(i) { i % 10 == 0 } then "decade"
    end

    View Slide

  149. Iteration #12
    class Bob
    def hey(input)
    case input
    when shout? then "Whoa, chill out!"
    when question? then "Sure."
    when silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?
    ->(s) { s.strip.empty? }
    end
    def question?
    ->(s) { s.end_with?("?") }
    end
    def shout?
    ->(s) { s == s.upcase && s != s.downcase }
    end
    end

    View Slide

  150. truth
    def question?
    ->(s) { s.end_with?("?") }
    end

    View Slide

  151. Proc.new{ false }
    truth

    View Slide

  152. truth

    View Slide

  153. !!Proc.new{ false }
    # => true
    truth

    View Slide

  154. private
    def silence?
    ->(s) { s.strip.empty? }
    end
    def question?
    ->(s) { s.end_with?("?") }
    end
    def shout?
    ->(s) { s == s.upcase && s != s.downcase }
    end
    Iteration #12

    View Slide

  155. private
    def silence?
    ->(s) { s.strip.empty? }
    end
    def question?
    ->(s) { s.end_with?("?") }
    end
    def shout?
    ->(s) { s == s.upcase && s != s.downcase }
    end
    Iteration #12
    private
    def silence?(s)
    s.strip.empty?
    end
    def question?(s)
    s.end_with?("?")
    end
    def shout?(s)
    s == s.upcase && s != s.downcase
    end

    View Slide

  156. take-away #12

    View Slide

  157. take-away #12
    don’t lie

    View Slide

  158. Iteration #13
    class Bob
    def hey(input)
    case
    when shout?(input) then "Whoa, chill out!"
    when question?(input) then "Sure."
    when silence?(input) then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?(s)
    s.strip.empty?
    end
    def question?(s)
    s.end_with?("?")
    end
    def shout?(s)
    s == s.upcase && s != s.downcase
    end
    end

    View Slide

  159. Iteration #13
    class Bob
    def hey(input)
    case
    when shout?(input) then "Whoa, chill out!"
    when question?(input) then "Sure."
    when silence?(input) then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?(s)
    s.strip.empty?
    end
    def question?(s)
    s.end_with?("?")
    end
    def shout?(s)
    s == s.upcase && s != s.downcase
    end
    end

    View Slide

  160. Iteration #13
    class Bob
    def hey(input)
    case
    when shout?(input) then "Whoa, chill out!"
    when question?(input) then "Sure."
    when silence?(input) then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?(s)
    s.strip.empty?
    end
    def question?(s)
    s.end_with?("?")
    end
    def shout?(s)
    s == s.upcase && s != s.downcase
    end
    end

    View Slide

  161. Iteration #13
    class Bob
    def hey(input)
    case
    when shout?(input) then "Whoa, chill out!"
    when question?(input) then "Sure."
    when silence?(input) then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    private
    def silence?(s)
    s.strip.empty?
    end
    def question?(s)
    s.end_with?("?")
    end
    def shout?(s)
    s == s.upcase && s != s.downcase
    end
    end

    View Slide

  162. Iteration #13
    class Bob
    def hey(input)
    case
    when input.shout? then "Whoa, chill out!"
    when input.question? then "Sure."
    when input.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end
    class String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  163. take-away #13

    View Slide

  164. take-away #13
    make your objects cohesive

    View Slide

  165. Iteration #14
    class Bob
    def hey(input)
    case
    when input.shout? then "Whoa, chill out!"
    when input.question? then "Sure."
    when input.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end
    class String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  166. String API

    View Slide

  167. String API
    #downcase
    #gsub
    #reverse
    #scan
    #squeeze
    #to_i
    ...

    View Slide

  168. String API
    #downcase
    #gsub
    #reverse
    #scan
    #squeeze
    #to_i
    ...
    #question?
    #shout?
    #silence?

    View Slide

  169. Iteration #14
    class Bob
    def hey(input)
    case
    when input.shout? then "Whoa, chill out!"
    when input.question? then "Sure."
    when input.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end
    class String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  170. Iteration #14
    class Bob
    def hey(input)
    input = Input.new(input)
    case
    when input.shout? then "Whoa, chill out!"
    when input.question? then "Sure."
    when input.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end
    class Input < String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  171. take-away #14

    View Slide

  172. take-away #14
    no, really, make ALL your
    objects cohesive

    View Slide

  173. Iteration #15
    class Bob
    def hey(input)
    input = Input.new(input)
    case
    when input.shout? then "Whoa, chill out!"
    when input.question? then "Sure."
    when input.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end
    end
    end
    class Input < String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  174. Input API
    #downcase
    #gsub
    #reverse
    #scan
    #squeeze
    #to_i
    ...
    #question?
    #shout?
    #silence?

    View Slide

  175. class DazzlingString < String
    def sparkle
    "**;* #{self} **;**"
    end
    end
    beware!

    View Slide

  176. s = DazzlingString.new("unicorn")
    beware!

    View Slide

  177. beware!

    View Slide

  178. beware!
    s.sparkle
    # => **;* unicorn **;**

    View Slide

  179. beware!
    s.sparkle
    # => **;* unicorn **;**
    s.upcase
    # => UNICORN

    View Slide

  180. beware!
    s.sparkle
    # => **;* unicorn **;**
    s.upcase
    # => UNICORN
    s << 's'
    # => "unicorns"

    View Slide

  181. beware!
    s.sparkle
    # => **;* unicorn **;**
    s.upcase
    # => UNICORN
    s << 's'
    # => "unicorns"
    s.sparkle
    # => **;* unicorns **;**

    View Slide

  182. beware!

    View Slide

  183. s1 = DazzlingString.new("unicorn")
    beware!

    View Slide

  184. s1 = DazzlingString.new("unicorn")
    s2 = DazzlingString.new("rainbow")
    beware!

    View Slide

  185. beware!

    View Slide

  186. s1.sparkle
    # => **;* unicorn **;**
    s2.sparkle
    # => **;* rainbow **;**
    beware!

    View Slide

  187. beware!

    View Slide

  188. beware!
    s3 = s1 + s2
    # => "unicornrainbow"

    View Slide

  189. beware!
    s3.sparkle
    # => undefined method `sparkle' for
    "unicornrainbow":String (NoMethodError)
    s3 = s1 + s2
    # => "unicornrainbow"

    View Slide

  190. Iteration #15
    class Bob
    # ...
    end
    class Input < String
    def silence?
    strip.empty?
    end
    def question?
    end_with?("?")
    end
    def shout?
    self == upcase && self != downcase
    end
    end

    View Slide

  191. Iteration #15
    class Bob
    # ...
    end
    class Input
    attr_reader :input
    def initialize(input)
    @input = input
    end
    def silence?
    input.strip.empty?
    end
    def question?
    input.end_with?("?")
    end
    def shout?
    input == input.upcase && input != input.downcase
    end
    end

    View Slide

  192. Input API
    #question?
    #shout?
    #silence?

    View Slide

  193. Input API
    #question?
    #shout?
    #silence?
    #downcase
    #gsub
    #reverse
    #scan
    #squeeze
    #to_i
    ...

    View Slide

  194. take-away #15

    View Slide

  195. take-away #15
    no, really, seriously,
    f’reals make your objects
    cohesive

    View Slide

  196. Iteration #16
    class Bob
    def hey(input)
    input = Input.new(input)
    case
    # ...
    end
    end
    end
    class Input
    attr_reader :input
    def initialize(input)
    @input = input
    end
    def silence?
    input.strip.empty?
    end
    def question?
    input.end_with?("?")
    end
    def shout?
    input == input.upcase && input != input.downcase
    end
    end

    View Slide

  197. Iteration #16
    class Bob
    def hey(input)
    input = Input.new(input)
    case
    # ...
    end
    end
    end
    class Input
    attr_reader :input
    def initialize(input)
    @input = input
    end
    def silence?
    input.strip.empty?
    end
    def question?
    input.end_with?("?")
    end
    def shout?
    input == input.upcase && input != input.downcase
    end
    end

    View Slide

  198. naming
    class String
    # ...
    end

    View Slide

  199. naming
    class Input
    # ...
    end

    View Slide

  200. naming
    class Analyzer
    # ...
    end

    View Slide

  201. naming
    class Parser
    # ...
    end

    View Slide

  202. naming
    class Classifier
    # ...
    end

    View Slide

  203. naming
    class Message
    # ...
    end

    View Slide

  204. naming
    class Comment
    # ...
    end

    View Slide

  205. naming
    class Statement
    # ...
    end

    View Slide

  206. naming
    class Utterance
    # ...
    end

    View Slide

  207. naming
    class Confrontation
    # ...
    end

    View Slide

  208. naming
    class Drivel
    # ...
    end

    View Slide

  209. naming
    class Blathering
    # ...
    end

    View Slide

  210. naming
    class Interpretation
    # ...
    end

    View Slide

  211. naming
    class Tone
    # ...
    end

    View Slide

  212. naming
    class Perception
    # ...
    end

    View Slide

  213. point of view
    shout?
    question?
    silence?

    View Slide

  214. point of view
    shout?
    question?
    silence?
    ➔ freaking_out?
    ➔ dumb_question?
    ➔ cold_shoulder?

    View Slide

  215. naming
    class Remark
    # ...
    end

    View Slide

  216. Iteration #16
    class Bob
    def hey(remark)
    remark = Remark.new(remark)
    case
    # ...
    end
    end
    end
    class Remark
    attr_reader :remark
    def initialize(remark)
    @remark = remark
    end
    def silence?
    remark.strip.empty?
    end
    def question?
    remark.end_with?("?")
    end
    def shout?
    remark == remark.upcase && remark != remark.downcase
    end
    end

    View Slide

  217. Iteration #16
    class Bob
    def hey(remark)
    remark = Remark.new(remark)
    case
    # ...
    end
    end
    end
    class Remark
    attr_reader :remark
    def initialize(remark)
    @remark = remark
    end
    def silence?
    remark.strip.empty?
    end
    def question?
    remark.end_with?("?")
    end
    def shout?
    remark == remark.upcase && remark != remark.downcase
    end
    end

    View Slide

  218. echoes
    remark = Remark.new(remark)
    remark.remark

    View Slide

  219. echoes
    host = host.host if host.host?

    View Slide

  220. echoes
    member.member.member

    View Slide

  221. echoes
    var srcData = data;
    if (data.data && data.data.data) {
    data = data.data.data;
    } else if (data.data) {
    data = data.data;
    }
    if (!data) {
    return;
    }

    View Slide

  222. echoes
    remark = Remark.new(remark)
    remark.remark

    View Slide

  223. echoes
    remark = Remark.new(text)
    remark.text

    View Slide

  224. take-away #16

    View Slide

  225. take-away #16
    naming is hard

    View Slide

  226. Final Solution
    class Bob
    def hey(text)
    remark = Remark.new(text)
    case
    # ...
    end
    end
    end
    class Remark
    attr_reader :text
    def initialize(text)
    @text = text
    end
    def silence?
    text.strip.empty?
    end
    def question?
    text.end_with?("?")
    end
    def shout?
    text == text.upcase && text != text.downcase
    end
    end
    case
    when remark.shout? then "Whoa, chill out!"
    when remark.question? then "Sure."
    when remark.silence? then "Fine. Be that way!"
    else
    "Whatever."
    end

    View Slide

  227. class Bob
    def hey (input )
    if input=="Tom-ay-to, tom-aaaah-to."
    return"Whatever."
    elsif input == "WATCH OUT!"
    return "Whoa, chill out!"
    elsif input == "Does this cryogenic chamber make me look fat?"
    return "Sure."
    elsif input== "You are, what, like 15?"
    return "Sure."
    elsif input == "Let's go make out behind the gym!"
    return "Whatever."
    elsif input == "It's OK if you don't want to go to the DMV."
    return "Whatever."
    Initial Solution

    View Slide

  228. practice
    toy problems

    View Slide

  229. <3
    thank you

    View Slide

  230. credits
    Simple Made Easy
    http://www.infoq.com/presentations/Simple-Made-Easy
    Rich Hickey
    5 elements of Effective Thinking
    Michael Starbird, Edward Burger
    Smalltalk Implementation Patterns
    Kent Beck
    Mark by Mark
    http://vimeo.com/79530470
    Sarah Gray

    View Slide

  231. The Devil is in the Details
    Katrina Owen
    @kytrinyx
    http://exercism.io

    View Slide