Pro Yearly is on sale from $80 to $50! »

Rewriting code and culture - RubyConf.pt

Rewriting code and culture - RubyConf.pt

4d1993f91aa4f2efccf08051205e3bad?s=128

Sabrina Leandro

September 16, 2015
Tweet

Transcript

  1. Rewriting code and culture Sabrina Leandro @saleandro

  2. 1. Lessons from a rewrite project 2. Some code 3.

    Cultural changes
  3. A story about…

  4. A metaphor

  5. A metaphor

  6. None
  7. This is hell!

  8. Lessons on rewriting code

  9. Know your product

  10. None
  11. None
  12. None
  13. That is, where the impact of the changes will be

    seen sooner. Start where it hurts the most
  14. songkick.com Rails app Ruby services

  15. songkick.com Rails app Ruby services

  16. songkick.com Rails app Ruby services Land of legacy dragons

  17. Build a new, simplified web app based on core iPhone

    features so that we can improve the immediate velocity roadblocks and move onto building quickly on top of this core foundation. One main goal
  18. Know when it ends

  19. Define project scope Know when it ends

  20. Define project scope Have a clear deadline Know when it

    ends
  21. Define project scope Have a clear deadline Weekly checkpoints Know

    when it ends
  22. Define project scope Have a clear deadline Weekly checkpoints Know

    when it ends
  23. Define project scope Have a clear deadline Weekly checkpoints No

    new features Know when it ends
  24. Deleting your favourite features is hard! But when you know

    your product, you can be ruthless. Deleting is faster than rewriting
  25. Changes in master. Release incrementally. Improve your release process. Validate

    your assumptions
  26. Fast release cycle needs fast build

  27. Fast release cycle needs fast build Delete or rewrite tests.

  28. Cost of making a small change must be small. Fast

    release cycle needs fast build Delete or rewrite tests.
  29. Cost of making a small change must be small. Monitor

    errors in production. Fast release cycle needs fast build Delete or rewrite tests.
  30. Learn to iterate

  31. Release cycle is more than software development. Learn to iterate

  32. Release cycle is more than software development. Learn to iterate

  33. Release cycle is more than software development. Give developers the

    right context, and trust them to make the right decisions. Learn to iterate
  34. New front-end architecture

  35. tickets attendance- listing venue-info related- events additional-details event-brief event-social the

    Event page
  36. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css
  37. The event brief component

  38. controllers/ events_controller. rb models/ event.rb page_models/ event.rb event/ brief.rb models/

    event.rb services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class EventsController < ApplicationController def show @page = PageModels::Event.new(event) end end
  39. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class PageModels::Event < PageModels::Base def brief PageModels::Event::Brief.new( @event) end end
  40. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class PageModels::Event::Brief def event_title @event.festival? ? @event.festival_name : @event.headliners.first.name end end
  41. None
  42. p { color: #000000; }

  43. p { color: #000000; } p { color: #008000 !important;

    }
  44. p { color: #000000; } p { color: #008000 !important;

    } p { color: #f80046 !really-important!; }
  45. Duplication in front-end code is okay. DRY is for domain

    models
  46. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css show.html.erb <div class=“primary”> <%= component(:brief, @page.brief)%> </div> _brief.html.erb <div class=“component brief”> <h1><%= brief.event_title %></h1> </div>
  47. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event- brief.css event.css @import ‘components/event- brief.css’; event-brief.css .brief h1 { color: #000000; } .brief p { color: #f80046; }
  48. From idea to code. Shared language

  49. First step towards a service-oriented architecture

  50. controllers/ events_controller. rb models/ event.rb page_models/ event.rb event/ brief.rb models/

    event.rb services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class EventsController < ApplicationController def show @event = Event.find(params[:id]) … end end class Event < ActiveRecord::Base end
  51. controllers/ events_controller. rb models/ event.rb page_models/ event.rb event/ brief.rb models/

    event.rb services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class EventsController < ApplicationController def show event = Models::Event.from_id params[:id] @page = PageModels::Event.new(event) end end
  52. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings.rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class Models::Event def self.from_id(id) data = Services.event_listings.event_ from_id(id) new(data) end def initialize(data) @id = data[‘id’] @date = Date.parse(data[‘date’]) # etc. end end
  53. controllers/ events_controller.rb models/ event.rb page_models/ event.rb event/ brief.rb models/ event.rb

    services/ event_listings. rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class Services::EventListings def event_from_id(id) ar_event = ::Event.find(id) ar_event.to_hash end end class Event < ActiveRecord::Base def to_hash { 'id' => id, 'date' => date.to_s, # etc. } end end
  54. songkick.com Rails app Ruby services Land of legacy dragons

  55. controllers/ events_controller.rb models/ page_models/ event.rb event/ brief.rb models/ event.rb services/

    event_listings. rb views/ events/ _brief.html.erb show.html.erb assets/ stylesheets/ event.css components/ event-brief.css class Services::EventListings def event_from_id(id) response = http.get(“/events/#{id}") JSON.parse(response.body) end end
  56. event-listings accounts trackings notifications songkick.com Rails app

  57. event-listings accounts trackings notifications songkick.com Rails app

  58. Land of legacy dragons event-listings accounts trackings notifications songkick.com Rails

    app
  59. None
  60. Happiness

  61. Cultural changes

  62. Rewriting culture

  63. Rewriting culture …through collaboration between developers, designers, product managers, testers,

    support team, etc…
  64. Rewriting culture …through collaboration between developers, designers, product managers, testers,

    support team, etc… Collaboration builds shared understanding.
  65. Business goals User needs Technical feasibility

  66. Business goals User needs Technical feasibility Product magic

  67. Product teams Product manager Design lead Tech lead

  68. Culture in practice

  69. • Shared language Culture in practice

  70. • Shared language • Small and frequent releases Culture in

    practice
  71. • Shared language • Small and frequent releases • Iterate

    design and product development Culture in practice
  72. Before Culture in practice

  73. Feature Kick-off meetings Before Culture in practice

  74. Culture in practice Before

  75. Culture in practice Designer and developer pairing Before

  76. A clean codebase is just a means to an end.

    Rewriting culture
  77. Learn to collaborate and work in a cross-functional team. For

    happier teams, better products, and even improved code quality. Rewriting culture
  78. Links The Client side of SOA http://devblog.songkick.com/2012/08/30/the-client- side-of-soa/ Path to

    SOA http://devblog.songkick.com/2012/09/06/the-path-to- soa/ Our object-based Rails frontend http://devblog.songkick.com/2012/09/14/our-object- based-rails- frontend/
  79. Thanks! Sabrina Leandro @saleandro