Belfast Ruby - Interesting things from the GitHub codebase

Ee5bae7fa46b3195869c285ecbb4619e?s=47 Coby Chapple
November 12, 2014

Belfast Ruby - Interesting things from the GitHub codebase

As part of Break (http://breakconf.org), I gave a talk at the Belfast Ruby (http://belfastruby.com/) meetup talking about a few interesting things from the GitHub codebase.

Ee5bae7fa46b3195869c285ecbb4619e?s=128

Coby Chapple

November 12, 2014
Tweet

Transcript

  1. Hi, I’m Coby.

  2. Hi, I’m @cobyism.

  3. Product design at GitHub.

  4. A selection of interesting* things I’ve learnt doing design at

    GitHub. *Actual levels of interestingness may vary.
  5. Let’s talk about Philosophy

  6. GitHub Zen

  7. • Responsive is better than fast. • It’s not fully

    shipped until it’s fast. • Anything added dilutes everything else. • Practicality beats purity. • Approachable is better than simple. • Mind your words, they are important. • Speak like a human. • Half measures are as bad as nothing at all. • Encourage flow. • Non-blocking is better than blocking. • Favor focus over features. • Avoid administrative distraction. • Design for failure. • Keep it logically awesome.
  8. Let’s talk about Practicality

  9. None
  10. None
  11. Technical scaling probably won’t be your problem.

  12. Choose technology your team can rely on.

  13. GitHub isn’t a Rails shop. It’s not even a Ruby

    shop. It’s a Unix shop. — @rtomayko “
  14. Let’s talk about Performance

  15. Event delegation $('.js-button').on 'click', -> …

  16. Event delegation $(document).on 'click', '.js-button', -> …

  17. Minimal SCSS

  18. Let’s talk about Complexity

  19. ViewModels

  20. <% if current_user.invitations_enabled? && @team.pending_invitations.any? && @team.adminable_by?(current_user) %> <h3>Pending invitations</h3>

    <% @team.pending_invitations.each do |…| %> … <% end %> <% end %>
  21. app/views/orgs/teams/show.html.erb app/view_models/orgs/teams/show_view.rb

  22. class Teams::ShowView < ViewModel attr_reader :team def show_pending_invitations? current_user.invitations_enabled? &&

    team.pending_invitations.any? && team.adminable_by?(current_user) end end
  23. <% if view.show_pending_invitations? %> <h3>Pending invitations</h3> <% view.team.pending_invitations.each do |…|

    %> … <% end %> <% end %>
  24. None
  25. None
  26. <% if current_repository.pushable_by?(current_user) %> <% if pull_request && pull_request.head_ref_deletable_by?(current_user) &&

    branch != current_repository.default_branch %> <%= link_to "Delete branch", … %> <% end %> <% end %> <% if view.can_delete_branch? %> <%= link_to "Delete branch", … %> <% end %>
  27. Feature flags

  28. module FeatureFlags def preview_features? staff? end def new_thing_enabled? preview_features? end

    end
  29. class User < ActiveRecord::Base include FeatureFlags end

  30. class ApplicationController flags = FeatureFlags.public_instance_methods delegate *flags, to: current_user, allow_nil:

    true helper_method *flags end
  31. <% if new_thing_enabled? %> … <% end %>

  32. <% if new_thing_enabled? %> … <% else %> … <%

    end %>
  33. class NewThingController < ApplicationController before_filter :ensure_new_thing_enabled def ensure_new_thing_enabled render_404 unless

    new_thing_enabled? end end
  34. module FeatureFlags def preview_features? staff? end def new_thing_enabled? preview_features? end

    end ⁉️
  35. module FeatureFlags def preview_features? staff? end def new_thing_enabled? preview_features? true

    end end ✨
  36. jnunemaker / flipper !

  37. Let’s talk about Tooling

  38. peek / peek !

  39. github / dat-science !

  40. require "dat/science" class YourApp::Widget def allows?(user) experiment = Dat::Science::Experiment.new "widget-permissions"

    do |e| e.control { model.check_user(user).valid? } e.candidate { user.can? :read, model } end experiment.run end end
  41. require "dat/science" class YourApp::Widget include Dat::Science def allows?(user) science "widget-permissions"

    do |e| e.control { model.check_user(user).valid? } e.candidate { user.can? :read, model } end end end
  42. github / dat-analysis !

  43. Let’s talk about Responsibility

  44. class StarsController < … areas_of_responsibility :explore … end

  45. class ReleasesController < … areas_of_responsibility :releases, :git … end

  46. class BranchesController < … areas_of_responsibility :pull_requests, :repo_browsing, :web_flow, :git …

    end
  47. --- # Areas of Responsibility in the github/github codebase 2fa:

    name: "Two-Factor Authentication" teams: - "@github/2fa" abilities: name: "Abilities" teams: - "@github/abilities" - "@github/abilibuddies" api: name: "API / OAuth" teams: - "@github/api" - "@github/oauth-of-tomorrow"
  48. None
  49. Lessons

  50. Design faces inwards too.

  51. Design cuts through the stack.

  52. Learn to code, but don’t get hung up.

  53. Learn to design, but don’t get hung up.

  54. Thanks! @cobyism