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

Ruby Book Club LIVE

Ruby Book Club LIVE

Hello and welcome to the Ruby Book Club! We’re delighted that you could join us.

Today we’re starting with section 4.9 in Avdi Grimm’s ‘Confident Ruby’: Replace “string typing” with classes.

As always, it doesn’t matter if you haven’t found time to do the reading. At the Ruby Book Club, we like to make sure that everyone is on the same page.

Nadia Odunayo

July 11, 2016
Tweet

More Decks by Nadia Odunayo

Other Decks in Technology

Transcript

  1. Ruby Book Club

    LIVE
    Nadia Odunayo
    @nodunayo
    @rubybookclub

    View full-size slide

  2. 1 hour of a
    Ruby book
    each week

    View full-size slide

  3. @saronyitbarek
    codenewbie.org

    View full-size slide

  4. @nodunayo
    ignition.works

    View full-size slide

  5. 4.9
    Replace “string typing”
    with classes

    View full-size slide

  6. Interactive!

    View full-size slide

  7. What did

    you make of the
    reading?

    View full-size slide

  8. Who’s done the
    reading?

    View full-size slide

  9. Let’s get started!

    View full-size slide

  10. “The string is a stark data structure…a
    perfect vehicle for hiding information.”
    — Alan Perlis
    p.84

    View full-size slide

  11. Alan J. Perlis
    (April 1, 1922 – February 7, 1990)

    View full-size slide

  12. String Typing

    View full-size slide

  13. Replace strings that have special
    meanings with user-defined types.”
    p.84

    View full-size slide

  14. Input data is represented as a
    specially-formatted String.
    p.84

    View full-size slide

  15. Input data is represented as a
    specially-formatted String.
    There are numerous case statements
    switching on the content of the
    String.
    p.84

    View full-size slide

  16. Polymorphism

    View full-size slide

  17. Can you spot any
    problems with this
    code?

    View full-size slide

  18. light = TrafficLight.new
    p.87

    View full-size slide

  19. light = TrafficLight.new
    light.change_to(“PROCEED”)
    p.87

    View full-size slide

  20. light = TrafficLight.new
    light.change_to(“PROCEED”)
    puts “Next state: #{light.next_state.inspect}”
    p.87

    View full-size slide

  21. Next state: nil

    View full-size slide

  22. Next state: nil

    View full-size slide

  23. None of the case
    statements end with
    else clauses.
    p.87

    View full-size slide

  24. Something doesn’t feel
    right…

    View full-size slide

  25. …so what can we do
    about it?

    View full-size slide

  26. What if we
    represented traffic
    light states as
    objects?

    View full-size slide

  27. So, let’s get rid of that
    other case statement…

    View full-size slide

  28. There were repetitive
    case statements all
    switching on the same
    variable.
    p.96

    View full-size slide

  29. It was too easy to
    introduce an invalid
    value for the @state
    variable.
    p.96

    View full-size slide

  30. “traffic light state”
    p.96

    View full-size slide

  31. “The key to working productively in an
    OO language is to make the type
    system and polymorphic method
    dispatch do the work for you.”

    — Avdi Grimm
    p.96

    View full-size slide

  32. See you next
    week?

    View full-size slide

  33. Do I need to
    convince you to
    come back next
    week?

    View full-size slide

  34. Here’s the thing…

    View full-size slide

  35. How do we

    level up

    as developers?

    View full-size slide

  36. How many technical
    books have you

    finished?

    View full-size slide

  37. Being in a book
    club is the answer.

    View full-size slide

  38. Being in a book
    club is the answer.

    View full-size slide

  39. Being in the Ruby
    Book Club is the
    answer.

    View full-size slide

  40. CRBOOKCLUB
    20% off
    confidentruby.com

    View full-size slide

  41. rubybookclub.com

    View full-size slide

  42. @rubybookclub

    View full-size slide

  43. See you next week.

    View full-size slide

  44. See you next week.
    Nadia Odunayo
    @nodunayo
    @rubybookclub
    Thank you!
    rubybookclub.com

    View full-size slide