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

Lightning Talk: Escaping the Tar Pit

Lightning Talk: Escaping the Tar Pit

Nobody wants to inherit a project that reeks but here we are: Stuck in the tar pit.

How can we get out? Could we have avoided it in the first place? 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.

This was a lightning talk presented at Scripted Philadelphia '23, a crossover meetup between Philly PUG, PhillyJS, and Phillyrb: https://www.eventbrite.com/e/scripted-philadelphia-a-python-javascript-and-ruby-joint-meetup-tickets-626403759507

Ernesto Tagwerker

June 30, 2023
Tweet

More Decks by Ernesto Tagwerker

Other Decks in Programming

Transcript

  1. Escaping


    The Tar Pit
    Ernesto Tagwerker (@etagwerker)


    Scripted Philadelphia, June 29th, 2023

    View full-size slide

  2. Founder & CTO


    @OmbuLabs

    View full-size slide

  3. 🇦🇷 Hi, I’m from Argentina


    🦅 I live in Philadelphia


    👨💻 I ❤ Open Source

    View full-size slide

  4. Open Source


    Maintainer


    rubycritic, skunk,


    bundler-leak, next_rails

    View full-size slide

  5. Productized Services


    FastRuby.io


    UpgradeJS.com

    View full-size slide

  6. OmbuLabs


    We ❤ Legacy Code


    We ❤/🤬 Tech Debt


    We ❤ Maintainable Code

    View full-size slide

  7. Chapter 1:


    The Tar Pit

    View full-size slide

  8. “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

    View full-size slide

  9. Tar Pit Symptoms


    > Projects running over budget


    > Taking forever to ship small changes


    > Sacri
    fi
    cing quality, increasing tech debt

    View full-size slide

  10. Part 1: Assessing
    the situation

    View full-size slide

  11. Tech Debt


    1. Code Coverage

    View full-size slide

  12. Tech Debt


    1. Code Coverage


    2. (Un)maintainable Code

    View full-size slide

  13. Code Coverage
    SimpleCov


    (github.com/colszowka/simplecov)

    View full-size slide

  14. Code Coverage


    # Gemfile


    group :test do


    gem "simplecov", require: false


    end


    View full-size slide

  15. 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


    View full-size slide

  16. Code Coverage


    $ COVERAGE=true rake test


    View full-size slide

  17. Code Coverage


    View full-size slide

  18. (Un)maintainable
    Code


    n options

    View full-size slide

  19. (Un)maintainable Code


    n options (
    fl
    og;
    fl
    ay; reek;
    churn; RubyCritic;
    MetricFu; attractor;
    rubocop; …)

    View full-size slide

  20. Churn


    “Code that is constantly
    changing is hard to maintain so
    that’s part of my app’s tech
    debt”

    View full-size slide

  21. Churn


    $ git log --follow --format=%h default.rb | cat


    573c8f5


    2ccc5b8


    b447bc3

    View full-size slide

  22. Churn


    $ git log --follow --format=%h default.rb | cat


    573c8f5


    2ccc5b8


    b447bc3


    # Churn Count = 3

    View full-size slide

  23. Complexity


    “Code that is super complex is
    hard to maintain so that’s part
    of my app’s tech debt”

    View full-size slide

  24. Complexity


    flog

    View full-size slide

  25. Complexity


    $ flog default.rb


    => 10.8: flog total

    View full-size slide

  26. 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


    View full-size slide

  27. Complexity


    $ flog foo.rb


    => 10.8: flog total

    View full-size slide

  28. (Un)maintainable code


    Churn


    vs.


    Complexity

    View full-size slide

  29. Churn
    Complexity
    100
    0
    1 100_000
    user.rb (changed: 2 times; complexity: 100_000 )

    View full-size slide

  30. Churn
    Complexity
    100
    0
    1 100_000
    user.rb
    (changed: 27 times; complexity: 100)

    View full-size slide

  31. (Un)maintainable Code


    RubyCritic


    (github.com/whitesmith/rubycritic)

    View full-size slide

  32. (Un)maintainable Code


    $ gem install rubycritic


    View full-size slide

  33. (Un)maintainable Code


    $ rubycritic


    View full-size slide

  34. GPA Pie Graph


    Complexity (flog)


    Code Smells (reek)

    View full-size slide

  35. RubyCritic


    module RubyCritic


    class AnalysedModule


    def cost


    smells.map(&:cost).inject(0.0, :+) +


    (complexity / COMPLEXITY_FACTOR)


    end


    end


    end

    View full-size slide

  36. RubyCritic


    module RubyCritic


    class AnalysedModule


    def cost


    smells.map(&:cost).inject(0.0, :+) + # From Reek


    (complexity / COMPLEXITY_FACTOR)


    end


    end


    end

    View full-size slide

  37. RubyCritic


    module RubyCritic


    class AnalysedModule


    def cost


    smells.map(&:cost).inject(0.0, :+) + # From Reek


    (complexity / COMPLEXITY_FACTOR) # From Flog


    end


    end


    end

    View full-size slide

  38. Churn vs.


    Complexity


    Churn (SCM)


    Complexity (flog)

    View full-size slide

  39. 100
    0
    1 100_000
    Complexity
    Churn

    View full-size slide

  40. 100
    0
    1 100_000
    “Welcome to


    the good place.” ❤
    Complexity
    Churn

    View full-size slide

  41. 100
    0
    1 100_000
    No one understands
    these
    fi
    les but they
    work. So don’t change
    them.
    Complexity
    Churn

    View full-size slide

  42. 100
    0
    1 100_000
    Everybody
    understands these
    fi
    les
    but you need to
    change them often
    Complexity
    Churn

    View full-size slide

  43. 100
    0
    1 100_000
    Complexity
    Churn
    These modules are
    complex and are


    constantly changing


    🤦 🤦 🤦

    View full-size slide

  44. 100
    0
    1 100_000
    Complexity
    Churn
    Refactoring level:
    Hard mode

    View full-size slide

  45. Are you getting into a tar
    pit, is it a dumpster
    fi
    re, or
    have you found a project
    which is easy to maintain?

    View full-size slide

  46. 100
    0
    1 100_000
    Welcome to the tar pit.
    Complexity
    Churn

    View full-size slide

  47. Tech Debt (Ruby)


    1. Code Coverage (SimpleCov)


    2. (Un)maintainable Code (RubyCritic)

    View full-size slide

  48. Tech Debt (JS)


    1. Code Coverage (Istanbul)


    2. (Un)maintainable Code (github.com/
    upgradejs/upjs-plato)

    View full-size slide

  49. You are here:

    View full-size slide

  50. Part 2: Getting out
    of the tar pit

    View full-size slide

  51. How can we gradually
    pay off technical debt?

    View full-size slide

  52. Measurable Metrics over


    Feelings (and Personal
    Opinions)

    View full-size slide

  53. Thank you!


    @etagwerker
    62
    ‣ github.com/whitesmith/rubycritic


    ‣ github.com/upgradejs/upjs-plato


    ‣ @OmbuLabs


    ‣ @FastRubyIO


    ‣ @JSupgrade

    View full-size slide

  54. Thank you!


    @etagwerker
    63
    Thank you!

    View full-size slide

  55. Resources
    1. https://github.com/whitesmith/rubycritic


    2.https://github.com/colszowka/simplecov


    3.https://github.com/metricfu/metric_fu


    4.https://github.com/julianrubisch/attractor


    5.https://www.fastruby.io/blog/ruby/quality/code-quality-ruby-gems.html


    6.https://www.reddit.com/r/ruby/comments/2bq092/rubycritic/


    7.http://jakescruggs.blogspot.com/2008/08/whats-good-
    fl
    og-score.html


    8.http://ruby.sadi.st/Flog.html


    9.http://ruby.sadi.st/Flay.html


    10.https://github.com/makaroni4/sandi_meter


    11.https://www.fastruby.io/blog/code-quality/intruducing-skunk-stink-score-
    calculator.html

    View full-size slide

  56. 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

    View full-size slide