Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

12 Hours To Rate A Rails Application

3,807 views

Published on

In some situations, it's useful to be able to evaluate a Rails application quickly.
I talk about how I work to get the most data as possible to get a good picture of whether an application is well-maintained, and will be easy to maintain later.

Published in: Technology
  • Be the first to comment

12 Hours To Rate A Rails Application

  1. 1. hours to rate a Rails application Elise Huard @elise_huard http://jabberwocky.eu Wednesday 31 March 2010
  2. 2. Acquisition Wednesday 31 March 2010
  3. 3. Maintenance Wednesday 31 March 2010
  4. 4. 12 hours To Rate a Rails Application 12:00 Wednesday 31 March 2010
  5. 5. Team Wednesday 31 March 2010
  6. 6. Team: use your gut Wednesday 31 March 2010
  7. 7. One man’s application Wednesday 31 March 2010
  8. 8. innovator automator Control Freak Wednesday 31 March 2010
  9. 9. ... Wednesday 31 March 2010
  10. 10. Vision Wednesday 31 March 2010
  11. 11. Methodology Wednesday 31 March 2010
  12. 12. Bug Tracker Version control Wednesday 31 March 2010
  13. 13. Back seat driver Wednesday 31 March 2010
  14. 14. 12 hours To Rate a Rails Application 10:00 Wednesday 31 March 2010
  15. 15. Try the app Wednesday 31 March 2010
  16. 16. does it work ? Wednesday 31 March 2010
  17. 17. 12 hours To Rate a Rails Application 09:45 Wednesday 31 March 2010
  18. 18. Rails version Wednesday 31 March 2010
  19. 19. plugins and gems Wednesday 31 March 2010
  20. 20. Wednesday 31 March 2010
  21. 21. managing updates piston git submodules (svn externals) Wednesday 31 March 2010
  22. 22. Licenses Wednesday 31 March 2010
  23. 23. NIH syndrom Wednesday 31 March 2010
  24. 24. 12 hours To Rate a Rails Application 09:00 Wednesday 31 March 2010
  25. 25. All that code Wednesday 31 March 2010
  26. 26. config/routes.rb map.root :controller => 'root', :action => 'index' map.namespace :admin do |admin| admin.resources :grids do |grid| grid.resources :nodes grid.resources :edges, :collection => {:all => :post, :update_all => :post} grid.resources :walkers end end map.resources :nodes, :only => [:new,:create,:show,:destroy], :collection => {:directions => :put} map.resources :walkers, :only => [:show,:new,:create,:destroy], :collection => {:select => :get} map.resources :itineraries, :only => [:show] map.four_oh_four '*path' , :controller => 'four_oh_fours' Wednesday 31 March 2010
  27. 27. models railroad -M | dot Tpng > models.png rubymine ctrl-alt-D uml dumper (needs maintenance) Wednesday 31 March 2010
  28. 28. names “There are only two hard things in Computer Science: cache invalidation and naming things” Phil Karlton Wednesday 31 March 2010
  29. 29. 12 hours To Rate a Rails Application 08:30 Wednesday 31 March 2010
  30. 30. Coffee Wednesday 31 March 2010
  31. 31. metrics Wednesday 31 March 2010
  32. 32. Know thine tools Wednesday 31 March 2010
  33. 33. LOC rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 2702 | 2150 | 36 | 158 | 4 | 11 | | Helpers | 358 | 303 | 0 | 22 | 0 | 11 | | Models | 1358 | 1104 | 30 | 117 | 3 | 7 | | Libraries | 2286 | 1655 | 38 | 152 | 4 | 8 | | Integration tests | 0 | 0 | 0 | 0 | 0 | 0 | | Functional tests | 1687 | 1322 | 31 | 195 | 6 | 4 | | Unit tests | 1356 | 1079 | 27 | 158 | 5 | 4 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 9747 | 7613 | 162 | 802 | 4 | 7 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 5212 Test LOC: 2401 Code to Test Ratio: 1:0.5 Wednesday 31 March 2010
  34. 34. RubyParser and Parsetree Ryan Davis and Eric Hodel (‘Ruby Sadists’) Wednesday 31 March 2010
  35. 35. RubyParser and Parsetree Abstract syntax tree RubyParser.new.parse(File.read(‘metrics.rb’),‘metric.rb’) class Metrics s(:class,:Metrics, nil, def probe s(:scope, s(:defn,:probe, puts "good" s(:args), end s(:scope, end s(:block, s(:call, nil, :puts, s(:arglist, s(:str, "good")))))))) Symbolic Expression (Sexp) Ruby2Ruby Wednesday 31 March 2010
  36. 36. flog ‘the pain your code is in’ Wednesday 31 March 2010
  37. 37. FLOG Weighing the AST with factors Assignment Branch Condition (ABC) def process_if(exp) add_to_score :branch process exp.shift # cond penalize_by 0.1 do process exp.shift # true process exp.shift # false end s() end Wednesday 31 March 2010
  38. 38. FLOG flog lib/flog.rb 647.8: flog total 13.8: flog/method average 87.5: Flog#output_details 58.8: Flog#process_iter 54.2: Flog#flog 48.8: Flog#parse_options 34.1: Flog#none 23.2: Flog#output_method_details 22.1: Flog#score_method 16.0: Flog#process_block_pass 15.6: Flog#report 15.2: Flog#expand_dirs_to_files 15.0: Flog#klass_name Wednesday 31 March 2010
  39. 39. FLOG Very good: < 20 All Right: < 50 Wednesday 31 March 2010
  40. 40. FLAY code similarities Wednesday 31 March 2010
  41. 41. FLAY RubyParser def mass @mass ||= self.structure.flatten.size end Hash of structure of nodes with mass > threshold self.hashes[node.structural_hash] << node analyze: if same hash = similar if same node = identical Wednesday 31 March 2010
  42. 42. FLAY flay *.rb Total score (lower is better) = 621 1) IDENTICAL code found in :defn (mass*2 = 188) channel.rb:48 clip.rb:80 2) Similar code found in :defn (mass = 93) channel.rb:150 clip.rb:110 clip.rb:116 3) Similar code found in :defs (mass = 58) contact.rb:32 contact.rb:37 Wednesday 31 March 2010
  43. 43. Saikuro cyclomatic complexity Wednesday 31 March 2010
  44. 44. Saikuro ruby-lex every keyword is interpreted into ‘state’ state used to calculate if, unless, while, until, for, elsif, when, rescue (blocks) Recursively Wednesday 31 March 2010
  45. 45. Saikuro Wednesday 31 March 2010
  46. 46. Saikuro Good: methods < 5 Wednesday 31 March 2010
  47. 47. Roodi Ruby Object Oriented Design Inferometer (what ?) “design issues” Wednesday 31 March 2010
  48. 48. Roodi RubyParser visitor pattern visitor: checker (Configurable) visitable: parsed nodes = extensible Wednesday 31 March 2010
  49. 49. Roodi app/controllers/itineraries_controller.rb:4 - Method name "show" cyclomatic complexity is 14. It should be 8 or less. app/models/itinerary.rb:41 - Block cyclomatic complexity is 6. It should be 4 or less. app/controllers/itineraries_controller.rb:4 - Method "show" has 30 lines. It should have 20 or less. app/helpers/application_helper.rb:27 - Method "clippy" has 26 lines. It should have 20 or less. Wednesday 31 March 2010
  50. 50. Reek Control Couple Data Clump Feature Envy Large Class Long Method Long Parameter List Simulated Polymorphism Uncommunicative Name Wednesday 31 March 2010
  51. 51. Reek RubyParser extends parsed nodes traverses nodes returns code after Ruby2Ruby Wednesday 31 March 2010
  52. 52. Reek UserSessionsController has no descriptive comment (Irresponsible Module) UserSessionsController#destroy calls current_user_session twice (Duplication) app/controllers/users_controller.rb -- 5 warnings: UsersController has no descriptive comment (Irresponsible Module) UsersController tests @aid_app at least 4 times (Simulated Polymorphism) UsersController#create calls params 3 times (Duplication) UsersController#create calls params[:user] 3 times (Duplication) ... Wednesday 31 March 2010
  53. 53. Churn Frequent changes may indicate issue Wednesday 31 March 2010
  54. 54. Churn Not only classes but also methods (RubyParser) Version control: git, Hg, svn Locates changes in source using logs (as in git log) Wednesday 31 March 2010
  55. 55. Churn +-------------------------------------------------+---------------+ | file_path | times_changed | +-------------------------------------------------+---------------+ | db/schema.rb | 26 | | config/routes.rb | 24 | | app/controllers/application_controller.rb | 22 | | app/controllers/add_apps_controller.rb | 22 | | config/environment.rb | 20 | | app/views/layouts/application.html.erb | 20 | | app/models/ability.rb | 18 | ... Wednesday 31 March 2010
  56. 56. Churn common sense ... mostly useful in maintenance phase Wednesday 31 March 2010
  57. 57. Rcov Wednesday 31 March 2010
  58. 58. Rcov Executes test keeps track of the executed lines Using C extension when possible to hook into MRI (experimental for 1.9) Wednesday 31 March 2010
  59. 59. Rcov Total coverage: comments included Wednesday 31 March 2010
  60. 60. Rcov good: 100% coverage Wednesday 31 March 2010
  61. 61. Heckle Wednesday 31 March 2010
  62. 62. Heckle ParseTree + Ruby2Ruby mutate doesn’t work for ruby 1.9 (ParseTree) time-consuming: combinatorials more for small programs (gems, scripts) Wednesday 31 March 2010
  63. 63. Heckle Initial tests pass. Let's rumble. ********************************************************************** *** AidApp#property_names loaded with 4 possible mutations ********************************************************************** 4 mutations remaining... Replacing AidApp#property_names with: --- original +++ mutation def property_names - (meta_policy and meta_policy.property_names_for(:aid_app)) + (nil and meta_policy.property_names_for(:aid_app)) end Wednesday 31 March 2010
  64. 64. rake stats size Flog Flay code complexity code similarities Roodi Saikuro Reek cyclomatic antipatterns complexity Heckle Rcov test coverage Wednesday 31 March 2010
  65. 65. metric_fu Wednesday 31 March 2010
  66. 66. 12 hours To Rate a Rails Application 06:30 Wednesday 31 March 2010
  67. 67. Lunch Wednesday 31 March 2010
  68. 68. and more Coffee Wednesday 31 March 2010
  69. 69. read some code Wednesday 31 March 2010
  70. 70. Expressive code Wednesday 31 March 2010
  71. 71. Database db/schema.rb seed data everything in migrations ? Wednesday 31 March 2010
  72. 72. Nested_has_many_through Wednesday 31 March 2010
  73. 73. views Bad: unindented divitis javascript in the body too much logic in viewiew Wednesday 31 March 2010
  74. 74. 12 hours To Rate a Rails Application 04:30 Wednesday 31 March 2010
  75. 75. run tests Wednesday 31 March 2010
  76. 76. Time for tests (or autotest/ci) Wednesday 31 March 2010
  77. 77. maintainable test suite tests = software changes in implementation changes in requirements Wednesday 31 March 2010
  78. 78. maintainable test suite express code responsibility hide incident detail DRY Wednesday 31 March 2010
  79. 79. 12 hours To Rate a Rails Application 02:30 Wednesday 31 March 2010
  80. 80. Deployment Wednesday 31 March 2010
  81. 81. Deployment Wednesday 31 March 2010
  82. 82. Deployment Automation, automation, automation Wednesday 31 March 2010
  83. 83. Deployment deployment = software same rules apply Wednesday 31 March 2010
  84. 84. Traffic Wednesday 31 March 2010
  85. 85. Performance tests Bottlenecks Wednesday 31 March 2010
  86. 86. 12 hours To Rate a Rails Application 01:00 Wednesday 31 March 2010
  87. 87. Brownie Points Wednesday 31 March 2010
  88. 88. Continuous integration ... and they’re using it Wednesday 31 March 2010
  89. 89. Documentation of any kind ... and it’s up to date Wednesday 31 March 2010
  90. 90. monitoring exception notification Log analyzers Wednesday 31 March 2010
  91. 91. testing javascripts Continuous performance testing Wednesday 31 March 2010
  92. 92. 12 hours To Rate a Rails Application 00:00 Wednesday 31 March 2010
  93. 93. http://railroad.rubyforge.org/ http://www.igvita.com/2008/12/11/ruby-ast-for-fun-and-profit/ http://ruby.sadi.st/Ruby_Sadist.html http://goruco2008.confreaks.com/04_davis.html http://cwd.dhemery.com/2009/11/wmaat/ http://c2.com/cgi/wiki?AbcMetric http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/title.htm http://blog.rubybestpractices.com/posts/judofyr/sexp-for- rubyists.html Elise Huard @elise_huard elise@elisehuard.be http://jabberwocky.eu Wednesday 31 March 2010

×