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

Wrangling Large Ruby Codebases @ Rocky Mountain Ruby 2012

shagemann
September 21, 2012

Wrangling Large Ruby Codebases @ Rocky Mountain Ruby 2012

As Rails applications grow they see a lot of the same problems that any enterprise level software project will see at some point: longer running test suites, more complex code interaction, and a rising requirement to keep "all that stuff" in your head at once.

Rails may have been a framework for single applications in the past, but it nowadays has some features that allow you to tackle bigger projects with more ease. We'll cover Rails code structuring techniques like unbuilt gems and engines that you can use to get faster test suites, cleaner structures, and more flexible apps.

shagemann

September 21, 2012
Tweet

More Decks by shagemann

Other Decks in Programming

Transcript

  1. Wrangling large Ruby
    codebases
    Stephan Hagemann
    Monday, September 24, 2012

    View Slide

  2. The next big Thing
    github.com/shageman/the_next_big_thing
    Monday, September 24, 2012

    View Slide

  3. Disclaimer: nothing I
    might say other people
    say, they actually say.
    except when I say so.
    Monday, September 24, 2012

    View Slide

  4. When you see this on a slide:
    the-next-big-thing.herokuapp.com/
    Monday, September 24, 2012

    View Slide

  5. When you see this on a slide:
    github.com/shageman/the_next_big_thing/
    Monday, September 24, 2012

    View Slide

  6. Let’s talk about large apps
    Monday, September 24, 2012

    View Slide

  7. Never build large apps.
    Monday, September 24, 2012

    View Slide

  8. Sandi:
    your app wants to
    kill you
    Monday, September 24, 2012

    View Slide

  9. Wrangling stuff
    Monday, September 24, 2012

    View Slide

  10. Monday, September 24, 2012

    View Slide

  11. HTTP://WWW.FLICKRIVER.COM/PHOTOS/REXY85/263649949/
    Monday, September 24, 2012

    View Slide

  12. HTTP://WWW.PBASE.COM/SIGMADSLR/IMAGE/34745521
    Monday, September 24, 2012

    View Slide

  13. HTTP://WWW.PELAPAPAS.COM.MX/HTMLS/GENTE_ANIMALES.HTML
    Monday, September 24, 2012

    View Slide

  14. Never build large apps.
    Monday, September 24, 2012

    View Slide

  15. So... I built a tiny app
    Monday, September 24, 2012

    View Slide

  16. Ok, ok... big apps
    Monday, September 24, 2012

    View Slide

  17. Monday, September 24, 2012

    View Slide

  18. ACCOUNT_DELETER.RB
    ACCOUNT_DELETION.RB
    APP_CONFIG.RB
    ASPECT.RB
    ASPECT_MEMBERSHIP.RB
    ASPECT_VISIBILITY.RB
    BLOCK.RB
    COMMENT.RB
    CONTACT.RB
    CONVERSATION.RB
    CONVERSATION_VISIBILITY.RB
    FEATURE_FLAGGER.RB
    INVITATION.RB
    INVITATION_CODE.RB
    LIKE.RB
    MENTION.RB
    MESSAGE.RB NOTIFICATION.RB
    NOTIFICATION_ACTOR.RB
    O_EMBED_CACHE.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_AUTHORIZATION.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_CLIENT.RB
    PARTICIPATION.RB
    PERSON.RB PHOTO.RB
    POD.RB
    POST.RB
    PROFILE.RB
    RELAYABLE_RETRACTION.RB
    REQUEST.RB
    RESHARE.RB
    RETRACTION.RB
    ROLE.RB
    SERVICE.RB
    SERVICE_USER.RB
    SHARE_VISIBILITY.RB
    SIGNED_RETRACTION.RB
    STATUS_MESSAGE.RB
    TAG_FOLLOWING.RB
    USER.RB
    USER_PREFERENCE.RB
    Monday, September 24, 2012

    View Slide

  19. Yehuda is like:
    grmpf! that’s like
    throwing all that on a big
    pile!! Ugly
    Monday, September 24, 2012

    View Slide

  20. HTTP://WWW.FLICKR.COM/PHOTOS/WIDNR/6589525327/
    Monday, September 24, 2012

    View Slide

  21. Structured
    Monday, September 24, 2012

    View Slide

  22. Comprehendible
    Monday, September 24, 2012

    View Slide

  23. Agile
    Monday, September 24, 2012

    View Slide

  24. Focused
    Monday, September 24, 2012

    View Slide

  25. Structured Prevent the big pile
    Comprehendible Prevent cognitive overload
    Agile Allow for change
    Focused Allow for concentration
    Monday, September 24, 2012

    View Slide

  26. ACCOUNT_DELETER.RB
    ACCOUNT_DELETION.RB
    APP_CONFIG.RB
    ASPECT.RB
    ASPECT_MEMBERSHIP.RB
    ASPECT_VISIBILITY.RB
    BLOCK.RB
    COMMENT.RB
    CONTACT.RB
    CONVERSATION.RB
    CONVERSATION_VISIBILITY.RB
    FEATURE_FLAGGER.RB
    INVITATION.RB
    INVITATION_CODE.RB
    LIKE.RB
    MENTION.RB
    MESSAGE.RB NOTIFICATION.RB
    NOTIFICATION_ACTOR.RB
    O_EMBED_CACHE.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_AUTHORIZATION.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_CLIENT.RB
    PARTICIPATION.RB
    PERSON.RB PHOTO.RB
    POD.RB
    POST.RB
    PROFILE.RB
    RELAYABLE_RETRACTION.RB
    REQUEST.RB
    RESHARE.RB
    RETRACTION.RB
    ROLE.RB
    SERVICE.RB
    SERVICE_USER.RB
    SHARE_VISIBILITY.RB
    SIGNED_RETRACTION.RB
    STATUS_MESSAGE.RB
    TAG_FOLLOWING.RB
    USER.RB
    USER_PREFERENCE.RB
    Monday, September 24, 2012

    View Slide

  27. Structured No.
    Comprehendible Hm.
    Agile Can’t tell.
    Focused Doesn’t seem so.
    Monday, September 24, 2012

    View Slide

  28. HTTP://WWW.FLICKR.COM/PHOTOS/CHAPSTICKADDICT/4721461500/
    HTTP://WWW.FLICKR.COM/PHOTOS/41597157@N00/2515819924/
    HTTP://WWW.FLICKR.COM/PHOTOS/41597157@N00/2475319232/
    HTTP://WWW.FLICKR.COM/PHOTOS/CHAPSTICKADDICT/4721461500/
    Monday, September 24, 2012

    View Slide

  29. ACCOUNT_DELETER.RB
    ACCOUNT_DELETION.RB
    APP_CONFIG.RB
    ASPECT.RB
    ASPECT_MEMBERSHIP.RB
    ASPECT_VISIBILITY.RB
    BLOCK.RB
    COMMENT.RB
    CONTACT.RB
    CONVERSATION.RB
    CONVERSATION_VISIBILITY.RB
    FEATURE_FLAGGER.RB
    INVITATION.RB
    INVITATION_CODE.RB LIKE.RB
    MENTION.RB
    MESSAGE.RB
    NOTIFICATION.RB
    NOTIFICATION_ACTOR.RB
    O_EMBED_CACHE.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_A
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_C
    PARTICIPATION.RB
    PERSON.RB
    PHOTO.RB
    POD.RB
    POST.RB
    PROFILE.RB
    RELAYABLE_RETRACTION.RB
    REQUEST.RB
    RESHARE.RB
    RETRACTION.RB
    ROLE.RB
    SERVICE.RB
    SERVICE_USER.RB
    SHARE_VISIBILITY.RB
    SIGNED_RETRACTION.RB
    STATUS_MESSAGE.RB
    TAG_FOLLOWING.RB
    USER.RB
    USER_PREFERENCE.RB
    Monday, September 24, 2012

    View Slide

  30. Matz is like:
    We got namespaces:
    modules!
    Monday, September 24, 2012

    View Slide

  31. ACCOUNT_DELETER.RB
    ACCOUNT_DELETION.RB
    APP_CONFIG.RB
    ASPECT.RB
    ASPECT_MEMBERSHIP.RB
    ASPECT_VISIBILITY.RB
    BLOCK.RB
    COMMENT.RB
    CONTACT.RB
    CONVERSATION.RB
    CONVERSATION_VISIBILITY.RB
    FEATURE_FLAGGER.RB
    INVITATION.RB
    INVITATION_CODE.RB LIKE.RB
    MENTION.RB
    MESSAGE.RB
    NOTIFICATION.RB
    NOTIFICATION_ACTOR.RB
    O_EMBED_CACHE.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_A
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_C
    PARTICIPATION.RB
    PERSON.RB
    PHOTO.RB
    POD.RB
    POST.RB
    PROFILE.RB
    RELAYABLE_RETRACTION.RB
    REQUEST.RB
    RESHARE.RB
    RETRACTION.RB
    ROLE.RB
    SERVICE.RB
    SERVICE_USER.RB
    SHARE_VISIBILITY.RB
    SIGNED_RETRACTION.RB
    STATUS_MESSAGE.RB
    TAG_FOLLOWING.RB
    USER.RB
    USER_PREFERENCE.RB
    Monday, September 24, 2012

    View Slide

  32. ACCOUNT_DELETER.RB
    ACCOUNT_DELETION.RB
    APP_CONFIG.RB
    ASPECT.RB
    ASPECT_MEMBERSHIP.RB
    ASPECT_VISIBILITY.RB
    BLOCK.RB
    COMMENT.RB
    CONTACT.RB
    CONVERSATION.RB
    CONVERSATION_VISIBILITY.RB
    FEATURE_FLAGGER.RB
    INVITATION.RB
    INVITATION_CODE.RB LIKE.RB
    MENTION.RB
    MESSAGE.RB
    NOTIFICATION.RB
    NOTIFICATION_ACTOR.RB
    O_EMBED_CACHE.RB
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_A
    OAUTH2_PROVIDER_MODELS_ACTIVERECORD_C
    PARTICIPATION.RB
    PERSON.RB
    PHOTO.RB
    POD.RB
    POST.RB
    PROFILE.RB
    RELAYABLE_RETRACTION.RB
    REQUEST.RB
    RESHARE.RB
    RETRACTION.RB
    ROLE.RB
    SERVICE.RB
    SERVICE_USER.RB
    SHARE_VISIBILITY.RB
    SIGNED_RETRACTION.RB
    STATUS_MESSAGE.RB
    TAG_FOLLOWING.RB
    USER.RB
    USER_PREFERENCE.RB
    User
    OAuth
    Interaction
    Memberships
    Don’t know
    Visibility
    Retraction
    Monday, September 24, 2012

    View Slide

  33. Structured One more level at least!
    Comprehendible Modules might make sense
    Agile No change
    Focused Can’t prove it
    Monday, September 24, 2012

    View Slide

  34. HTTP://WWW.FLICKR.COM/PHOTOS/BRENDA-STARR/3466702375/
    Monday, September 24, 2012

    View Slide

  35. Carl is like:
    Gems!!
    Monday, September 24, 2012

    View Slide

  36. Ben is like:
    Depend upon
    abstractions!
    Monday, September 24, 2012

    View Slide

  37. I am like:
    Yes, but don’t put
    PaymentGateway in lib,
    put it in a gem!
    Monday, September 24, 2012

    View Slide

  38. Gems bring their own
    specs with them!
    Monday, September 24, 2012

    View Slide

  39. Choose modules that
    tell the story of the
    system and contain a
    cohesive set of concepts
    -- Eric Evans
    Monday, September 24, 2012

    View Slide

  40. Choose modules that
    tell the story of the
    system and contain a
    cohesive set of concepts
    -- Eric Evans
    Monday, September 24, 2012

    View Slide

  41. higher cohesion inside
    looser coupling outside
    Monday, September 24, 2012

    View Slide

  42. The annoyance problem
    Monday, September 24, 2012

    View Slide

  43. The annoyance gem
    Monday, September 24, 2012

    View Slide

  44. Structured Yes!
    Comprehendible The gem is only dealing with its stuff
    Agile git submodule? separate repo? hm.
    Focused Yes! And you can prove it!
    Monday, September 24, 2012

    View Slide

  45. You guys are like:
    Git submodules
    suck!!
    Monday, September 24, 2012

    View Slide

  46. I am like:
    Yep.
    Use unbuilt gems!
    Monday, September 24, 2012

    View Slide

  47. Gemfiles require by path
    Monday, September 24, 2012

    View Slide

  48. Explicit dependencies!
    Monday, September 24, 2012

    View Slide

  49. Structured Yes!
    Comprehendible Yes!
    Agile Yes!
    Focused Yes!
    Monday, September 24, 2012

    View Slide

  50. Current Pivotal project
    Availability
    and
    Booking
    Rails Travel Site
    Payment
    Gateway
    Conversion
    Tracking
    Monday, September 24, 2012

    View Slide

  51. But wait...
    Monday, September 24, 2012

    View Slide

  52. DHH is like:
    What about Rails?
    Monday, September 24, 2012

    View Slide

  53. Structured Yes!
    Comprehendible Yes!
    Agile Yes!
    Focused Yes!
    Rails? hm.
    Monday, September 24, 2012

    View Slide

  54. José is like:
    I got this. Engines!
    Monday, September 24, 2012

    View Slide

  55. Engines are not just for
    pagination, generic
    admin, and authentication
    Monday, September 24, 2012

    View Slide

  56. Engines are not just
    kaminari, generic admin,
    and authentication
    Monday, September 24, 2012

    View Slide

  57. Engines are not just
    kaminari, active admin,
    and authentication
    Monday, September 24, 2012

    View Slide

  58. Engines are not just
    kaminari, active admin,
    and devise
    Monday, September 24, 2012

    View Slide

  59. Rails::Engine allows you to wrap a
    specific Rails application or subset of
    functionality and share it with other
    applications.
    -- http://api.rubyonrails.org/
    Monday, September 24, 2012

    View Slide

  60. Rails::Engine allows you to wrap a
    specific Rails application or subset of
    functionality and share it with
    yourself.
    -- Me
    Monday, September 24, 2012

    View Slide

  61. Engines are easy
    Monday, September 24, 2012

    View Slide

  62. Structured Yes!
    Comprehendible Yes!
    Agile Yes!
    Focused Yes!
    Rails? Yes!
    Monday, September 24, 2012

    View Slide

  63. Details
    Monday, September 24, 2012

    View Slide

  64. Engines are not magical!
    Monday, September 24, 2012

    View Slide

  65. Mounting
    Monday, September 24, 2012

    View Slide

  66. Assets
    Monday, September 24, 2012

    View Slide

  67. Migrations
    Monday, September 24, 2012

    View Slide

  68. Current Pivotal Project
    Rails TV Shows with Social Network
    Global Admin Show Admin
    SMS Interface
    Social Network
    Publisher
    Admin UI
    Users and
    Channels
    Monday, September 24, 2012

    View Slide

  69. Both gems and engines
    are just
    Monday, September 24, 2012

    View Slide

  70. If you do them right,
    they tell the story of
    your app
    Monday, September 24, 2012

    View Slide

  71. Do one thing
    Monday, September 24, 2012

    View Slide

  72. All
    gems
    start with a namespace
    Monday, September 24, 2012

    View Slide

  73. No
    Rails app
    starts with a namespace
    Monday, September 24, 2012

    View Slide

  74. Rails Gems
    Monday, September 24, 2012

    View Slide

  75. Try this!
    Namespace everything
    in your next Rails app
    Monday, September 24, 2012

    View Slide

  76. Give yourself a box so
    you can start thinking
    outside of it
    Monday, September 24, 2012

    View Slide

  77. Thanks!
    Monday, September 24, 2012

    View Slide

  78. Stephan Hagemann
    [email protected]
    @shageman
    github.com/shageman
    pivotallabs.com/users/shagemann/blog
    Monday, September 24, 2012

    View Slide

  79. “The secret to building large apps is
    never build large apps. Break your
    application into small pieces. Then,
    assemble those testable, bite-sized
    pieces into your big application”
    -- Justin Meyer, JavascriptMVC
    Monday, September 24, 2012

    View Slide