Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stuck in the Tar Pit at Sin City Ruby '24

Stuck in the Tar Pit at Sin City Ruby '24

Nobody wants to inherit a project that reeks but here we are: Stuck in the tar pit. How did we get here? In this talk you will learn how to use a few, great Ruby gems that will guide you out of that sticky tar you are in.

Ernesto Tagwerker

March 22, 2024
Tweet

More Decks by Ernesto Tagwerker

Other Decks in Programming

Transcript

  1. “Large-system programming has over the past decade been such a

    tar pit, and many great and powerful beasts have thrashed violently in it.” Fred Brooks
  2. “The fi ercer the struggle, the more entangling the tar,

    and no beast is so strong or so skillful but that they ultimately sink.” Fred Brooks
  3. Tech Debt Categories at Google 💸 (1) Migration is needed

    💸 (2) Outdated documentation 💸 (3) Insuf fi cient testing 💸 (4) Code quality 💸 (5) Dead/Abandoned code
  4. Tech Debt Categories at Google 💸 (6) Code degradation 💸

    (7) Team lacks necessary expertise 💸 (8) Unstable Dependencies 💸 (9) Migration was poorly executed 💸 (10) Sub-optimal release process
  5. Dependencies $ libyear-bundler Gemfile System is 56.5 libyears behind Total

    releases behind: 209 Major, minor, patch versions behind: 4, 65, 15
  6. Code Coverage # spec/spec_helper.rb if ENV["COVERAGE"] == "true" require 'simplecov'

    SimpleCov.start do add_group "Models", "models" add_filter "/spec/" track_files "**/*.rb" end end
  7. Code Quality n options ( fl og; fl ay; reek;

    churn; RubyCritic; MetricFu; attractor; rubocop; fukuzatsu; turbulence; …)
  8. Complexity class Default def yay # 10.8 = a =

    eval "1+1" # 1.2 + 6.0 + if a == 2 # 1.2 + 1.2 + puts "yay" # 1.2 end end end
  9. RubyCritic module RubyCritic class AnalysedModule def cost smells.map(&:cost).inject(0.0, :+) +

    # From Reek (complexity / COMPLEXITY_FACTOR) # From Flog end end end
  10. 100 0 1 100_000 No one understands these fi les

    but they work. So don’t change them. Complexity Churn
  11. 100 0 1 100_000 “[…], if the code never changes,

    it's not costing us money.” Sandi Metz Complexity Churn
  12. 100 0 1 100_000 Everybody understands these fi les but

    you need to change them often Complexity Churn
  13. 100 0 1 100_000 Complexity Churn These modules are complex

    and are constantly changing 🤦 🤦 🤦
  14. 100 0 1 100_000 Complexity Churn “Sometimes a class becomes

    so complex that refactoring seems too dif fi cult.” Michael Feathers
  15. user.rb complexity: 10 smells: 10 churn: 10 tech debt points:

    1,000 (10*10*10) account.rb complexity: 10 smells: 10 churn: 10 tech debt points: 1,000 (10*10*10)
  16. user.rb complexity: 10 smells: 10 churn: 10 code_coverage: 0 tech

    debt points: 100,000 (10*10*10*100) account.rb complexity: 10 smells: 10 churn: 10 code_coverage: 100 tech debt points: 1,000 (10*10*10*1)
  17. user.rb complexity: 10 smells: 10 churn: 10 code_coverage: 0 tech

    debt points: 100,000 (10*10*10*100) More tests for user.rb? 😉 account.rb complexity: 10 smells: 10 churn: 10 code_coverage: 100 tech debt points: 1,000 (10*10*10*1)
  18. user.rb complexity: 10 smells: 10 churn: 10 code_coverage: 0 tech

    debt points: 100,000 (10*10*10*100) account.rb complexity: 10 smells: 10 churn: 10 code_coverage: 100 tech debt points: 1,000 (10*10*10*1) Refactor account.rb? 😉
  19. Skunk $ skunk ... Skunk Score Total: 13231.069999999996 Modules Analysed:

    71 Skunk Score Average: 186.3530985915493 Worst Skunk Score: 2401.75 (lib/rubycritic/source_control_systems/git.rb)
  20. Skunk module RubyCritic class AnalysedModule def skunk_score return cost if

    perfect_coverage? cost * (PERFECT_COVERAGE - coverage.to_i) end end end
  21. Skunk module RubyCritic class AnalysedModule def skunk_score return cost if

    perfect_coverage? cost * (PERFECT_COVERAGE - coverage.to_i) # Penalty Factor = 100% - 20% => 80 end end end
  22. Resources 1.https://codeclimate.com/blog/deciphering-ruby-code-metrics/ 2.https://www.stickyminds.com/article/getting-empirical-about-refactoring 3.https://www.sandimetz.com/blog/2017/9/13/breaking-up-the-behemoth 4.https://github.com/troessner/reek 5.https://github.com/seattlerb/ fl ay 6.https://github.com/seattlerb/ fl

    og 7.http://www.sqa.net/iso9126.html 8.https://www.slideshare.net/mscottford/important-metrics-for-measuring-code-health 9.https://dilbert.com/strip/2006-12-08 10.https://www.fastruby.io/blog/ruby/quality/code-quality-ruby-gems.html 11.https://www.fastruby.io/blog/code-quality/code-coverage/rubycritic-4-2-0- simplecov-support.html
  23. Resources 1. https://www.ombulabs.com/blog/tech-debt-maturity-model.html 2. https://www.computer.org/csdl/magazine/so/ 2023/03/10109339/1MESXKyAYNO 3. https://www.linkedin.com/pulse/how-google-measures-manages- tech-debt-abi-noda/ 4.

    https://www.forbes.com/sites/rogerdooley/2023/01/06/southwest- meltdown-could-cost-825-million/?sh=672485e8709f 5. https://www.ciodive.com/news/southwest-invests-billions-technology- cloud/705898/ 6. https://ieeexplore.ieee.org/document/10109339