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

Viking Code School Presents Christopher Hendrix of Pivotal Labs

Viking Code School Presents Christopher Hendrix of Pivotal Labs

A materials science engineer by training, a developer by profession, and a designer by passion, Chris will be speaking about object orientation in Ruby.

Viking Education

July 10, 2015
Tweet

More Decks by Viking Education

Other Decks in Technology

Transcript

  1. @materialdesignr #goodobjects What Makes a Good Object? Christopher Hendrix

  2. @materialdesignr #goodobjects This talk’s Presenter

  3. @materialdesignr #goodobjects This talk’s • How to make objects/methods that

    are: • Sane • Confident • Consistent Goal
  4. @materialdesignr #goodobjects This talk’s Guide

  5. @materialdesignr #goodobjects This talk’s • 5 Family Member “Guiding Principles”

    • Quote • Theory/Introduction • Code Examples • Summary • Extra Reading • Q&A Structure
  6. @materialdesignr #goodobjects Think like a Teenager

  7. @materialdesignr #goodobjects ―Teenager “I will never grow up.”

  8. @materialdesignr #goodobjects Think like a • Values vs Entities •

    Colors/Numbers vs People
 • Can a Person be a Value Type? • Is teleportation murder? Teenager
  9. @materialdesignr #goodobjects Think like a Teenager • Fundamental Attributes

  10. @materialdesignr #goodobjects Think like a Teenager • Fundamental Attributes Start

    End Duration
  11. @materialdesignr #goodobjects Think like a Teenager • Fundamental Attributes •

    Computed Properties Start End Duration
  12. @materialdesignr #goodobjects Think like a Teenager • Designated Initializer
 •

    Custom Initializers
  13. @materialdesignr #goodobjects Think like a Teenager • What about 


    Freeform Objects?
  14. @materialdesignr #goodobjects Think like a Teenager • “Subtyping”

  15. @materialdesignr #goodobjects Think like a Teenager • Hide your “Subtyping”

  16. @materialdesignr #goodobjects Think like a • Separate Fundamental Attributes from

    Computed Properties • Think of a single Designated Initializer • Use Custom Initializers which delegate • Hide your “Subtyping” Teenager
  17. @materialdesignr #goodobjects Think like a Child

  18. @materialdesignr #goodobjects ―Child “But you promised!”

  19. @materialdesignr #goodobjects • f(x) = x^2 • A transformation •

    What makes f(x) a Good Function? Think like a Child
  20. @materialdesignr #goodobjects “A function is a relation between a set

    of inputs and a set of permissible outputs with the property that each input is related to exactly one output.” All Integer 1 2 3 ⋮ + Integer 1 4 9 ⋮
  21. @materialdesignr #goodobjects • f(x) = x^2 • A Good Function

    has • Consistent Input Types • Consistent Output Types • Well defined relation from each input to output Think like a Child Integer 1 2 3 ⋮ Integer 1 4 9 ⋮
  22. @materialdesignr #goodobjects Think like a Child

  23. @materialdesignr #goodobjects Think like a Child

  24. @materialdesignr #goodobjects Think like a Child

  25. @materialdesignr #goodobjects Think like a • Think of your function’s

    Type Signatures • Have consistent outputs • Use Arrays to encode potential failure Child
  26. @materialdesignr #goodobjects Think like an Adult

  27. @materialdesignr #goodobjects ―Adult “No.”

  28. @materialdesignr #goodobjects Think like an • Not everyone else makes

    good functions • Function dependencies are 
 sources of uncertainty Adult
  29. @materialdesignr #goodobjects Think like an Adult

  30. @materialdesignr #goodobjects Think like an Adult

  31. @materialdesignr #goodobjects Think like an Adult • Reject Unworkable Values


  32. @materialdesignr #goodobjects Think like an Adult • NaN


  33. @materialdesignr #goodobjects Think like an Adult • Does this help?


  34. @materialdesignr #goodobjects Think like an Adult • Reject Values at

    entry points
  35. @materialdesignr #goodobjects Think like an Adult • Wrap External Objects

  36. @materialdesignr #goodobjects Think like an • Say No to bad

    dependencies • Earliest Possible Rejection • Wrap External Objects in Confident Values Adult
  37. @materialdesignr #goodobjects Think like a Senior

  38. @materialdesignr #goodobjects ―Senior “Who are you?”

  39. @materialdesignr #goodobjects Think like a Senior

  40. @materialdesignr #goodobjects Think like a Senior • Accessing Data

  41. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages Senior @materialdesignr Sally Bob Age:
 24 24
  42. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages Senior Sally Bob Age:
 24 29 Age? def age if trying_to_impress? return @age + 5 else return @age end end
  43. @materialdesignr #goodobjects Think like a • Is it really Data?

    • Functions vs. Methods vs. Messages • Same Message, Different Methods Senior Sally Harry Age:
 32 32 Age? def age # I’m honest return @age end
  44. @materialdesignr #goodobjects Think like a Senior • Queries • Commands

  45. @materialdesignr #goodobjects Think like a Senior • Queries • Commands

  46. @materialdesignr #goodobjects Think like a • There is No Data,

    Only Zuul Messages • Ask Nicely instead of grabbing internals • Tell Confidently instead of DIY Senior
  47. @materialdesignr #goodobjects Think like a Baby

  48. @materialdesignr #goodobjects ―Baby “Who am I?”

  49. @materialdesignr #goodobjects Think like a • What’s so special about

    me? • Everything is message sending • Messages to Self Baby
  50. @materialdesignr #goodobjects Think like a Baby

  51. @materialdesignr #goodobjects Think like a Baby • Accessing Data

  52. @materialdesignr #goodobjects Think like a Baby • Messages to Self

    • Information Hiding
  53. @materialdesignr #goodobjects Think like a • Other Methods should be

    treated like Other Objects • Hide your own data Baby
  54. @materialdesignr #goodobjects This talk’s • Teenager — Make your constructors

    matter • Child — Think about function signatures • Adult — Use errors to prevent unknown state • Senior — Send messages to other objects • Baby — Send messages to yourself Summary
  55. @materialdesignr #goodobjects Reading is Practical Object Oriented Design in Ruby


    ―Sandi Metz Confident Ruby
 ―Avdi Grimm Refactoring
 ―Martin Fowler Fundamental
  56. @materialdesignr #goodobjects Questions & Answers

  57. @materialdesignr #goodobjects This talk’s • www.materialdesignr.com • @materialdesignr • github.com/chendrix

    • linkedin.com/in/materialdesignr Self-Promotion