RESCUE SQUADRAILS EDITIONRails Israel 2014
View Slide
@benlovelltwitter/github/irc
❤
railssucks
$ rails new life_is_good
I reallysuck!
Here’s some commitsI made just the other day
! "
Programming is likeskipping merrily betweencar crashes
ME!
WHY!!!!?!
TeamTransience
Make it workMake it rightMake it fast
Is it done yet?Is it done yet?Is it done yet?
!!!
RailsDerailed
Changingrequirements
sorryYour project isnot a special ❄
Quit whining!
No. 1best job?
$ git clone ...
Huge pile of shit?
!"GTFO?
5Steps
1Step
Perceptionchange it!
I seedeadpeople
Being apositiveinfluence
Opinions aspull requests
Broken windows
Strategise
Always leave the campcleaner than you found it
It’s better toseek forgivenessthan ask permission
Docs
2step
Metrics
CI
!
Effect a style guide
Make itapproachable
Rubocop
$ gem install rubocop~/code/frontend % rubocopInspecting 313 files.....................................................C...................................................................................................................................................................................................................................................................Offenses:app/helpers/profile_helper.rb:2:1: C: Extra empty line detected at body beginning.313 files inspected, 1 offense detected
Autocorrect?
~/code/frontend % rubocop -aInspecting 313 files.....................................................COffenses:app/helpers/profile_helper.rb:2:1: C: [Corrected] Extraempty line detected at body beginning.313 files inspected, 1 offense detected, 1 offense corrected
Sorcery!
Test Coverage
$ gem install SimpleCov
You're sitting on athrone of lies
Cyclomatic Complexity
$ gem install metric_fu-Saikuro
Coverage + Cyclomatic ComplexityInform your tests
DuplicationDuplicationDuplicationDuplication
$ gem install flay~/code/frontend % flay app/**/*.rb -fTotal score (lower is better) = 2561) Similar code found in :call (mass = 148)app/controllers/styleguide_controller.rb:63app/controllers/styleguide_controller.rb:2212) Similar code found in :defn (mass = 108)app/helpers/application_helper.rb:2app/helpers/application_helper.rb:9app/helpers/application_helper.rb:16app/helpers/application_helper.rb:23app/helpers/application_helper.rb:30app/helpers/application_helper.rb:37
Not allduplication
Good DRYBad DRY
singleunambiguousauthoritativerepresentation
Churn
$ gem install churn~/code/blog % churnFiles+----------------------------------------------------------+---------------+| file_path | times_changed |+----------------------------------------------------------+---------------+| Gemfile | 20 || app/helpers/application_helper.rb | 14 || app/models/article.rb | 11 || spec/models/text_filter_spec.rb | 11 || spec/controllers/articles_controller_spec.rb | 11 || spec/controllers/setup_controller_spec.rb | 11 || spec/rails_helper.rb | 10 || app/models/blog.rb | 10 || spec/models/article_spec.rb | 10 || spec/controllers/admin/content_controller_spec.rb | 10 || spec/helpers/application_helper_spec.rb | 10 |+----------------------------------------------------------+---------------+
Lines of Code
$ rake stats+----------------------+-------+-------+---------+---------+-----+-------+| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |+----------------------+-------+-------+---------+---------+-----+-------+| Controllers | 1995 | 1613 | 34 | 179 | 5 | 7 || Helpers | 485 | 401 | 0 | 67 | 0 | 3 || Models | 2793 | 2196 | 45 | 352 | 7 | 4 || Mailers | 37 | 31 | 1 | 5 | 5 | 4 || Javascripts | 31894 | 17140 | 0 | 1553 | 0 | 9 || Libraries | 2455 | 1878 | 85 | 233 | 2 | 6 || Controller specs | 3468 | 2801 | 0 | 16 | 0 | 173 || Helper specs | 264 | 213 | 1 | 3 | 3 | 69 || Lib specs | 247 | 195 | 0 | 0 | 0 | 0 || Model specs | 3970 | 3241 | 1 | 21 | 21 | 152 || Routing specs | 109 | 89 | 0 | 0 | 0 | 0 || Service specs | 125 | 103 | 0 | 0 | 0 | 0 || Uploader specs | 9 | 8 | 0 | 0 | 0 | 0 || View specs | 975 | 788 | 0 | 20 | 0 | 37 |+----------------------+-------+-------+---------+---------+-----+-------+| Total | 48826 | 30697 | 167 | 2449 | 14 | 10 |+----------------------+-------+-------+---------+---------+-----+-------+Code LOC: 23259 Test LOC: 7438 Code to Test Ratio: 1:0.3
All the metrics!$ gem install metric_fucane, churn, flog, flay, reekroodi, saikuro, code statisticsrails best practices
MetricOverflow!
Only capture thatyou plan to action
Make itknown
Dashboard
Gamify
3step
Tests
% tree spec/modelsspec/models├── authentication_token_spec.rb├── challenge_spec.rb├── entry_spec.rb├── facebook_token_spec.rb├── follow_spec.rb├── followed_list_spec.rb├── item_spec.rb├── list_fulfilment_criterion_spec.rb├── list_spec.rb├── prize_spec.rb├── rating_spec.rb└── user_spec.rb0 directories, 12 files
require 'test_helper'class UserTest < ActiveSupport::TestCase# test "the truth" do# assert true# endend
All kinds ofbad
No testsSlow testsLow quality tests
Tests are notsacred artifacts
Tests can betransient
zero coverage?this might not be so bad
Feature specsgo full stack or go home
Poor or slow units?wrong time, wrong place
Repeat after me:Tests are notsacred artifacts
kill them with fire
4step
Seekanddestroy
Reduce thesurfacearea
Always be merciless
Low hanging fruitTargets or goals which areeasily achievable but donot require lots of effort
ImproveIncrementally
Katrina Owen@kytrinyx
If you're especially brave...
$ bundle outdated
5step
Keep it full unicorn
Fail the build
Always beimproving
PerceptionMetricsTestsReduce or ImproveStay Full Unicorn
Thanks!@benlovell