Slide 1

Slide 1 text

Escaping The Tar Pit Ernesto Tagwerker (@etagwerker) Scripted Philadelphia, June 29th, 2023

Slide 2

Slide 2 text

Founder & CTO @OmbuLabs

Slide 3

Slide 3 text

🇦🇷 Hi, I’m from Argentina 🦅 I live in Philadelphia 👨💻 I ❤ Open Source

Slide 4

Slide 4 text

Open Source Maintainer rubycritic, skunk, bundler-leak, next_rails

Slide 5

Slide 5 text

Productized Services FastRuby.io UpgradeJS.com

Slide 6

Slide 6 text

OmbuLabs We ❤ Legacy Code We ❤/🤬 Tech Debt We ❤ Maintainable Code

Slide 7

Slide 7 text

Inspiration

Slide 8

Slide 8 text

Chapter 1: The Tar Pit

Slide 9

Slide 9 text

“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

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Tar Pit Symptoms > Projects running over budget > Taking forever to ship small changes > Sacri fi cing quality, increasing tech debt

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Part 1: Assessing the situation

Slide 14

Slide 14 text

Tech Debt

Slide 15

Slide 15 text

Tech Debt 1. Code Coverage

Slide 16

Slide 16 text

Tech Debt 1. Code Coverage 2. (Un)maintainable Code

Slide 17

Slide 17 text

Code Coverage SimpleCov (github.com/colszowka/simplecov)

Slide 18

Slide 18 text

Code Coverage # Gemfile group :test do gem "simplecov", require: false end

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Code Coverage $ COVERAGE=true rake test

Slide 21

Slide 21 text

Code Coverage

Slide 22

Slide 22 text

(Un)maintainable Code n options

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Churn

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Churn $ git log --follow --format=%h default.rb | cat 573c8f5 2ccc5b8 b447bc3

Slide 27

Slide 27 text

Churn $ git log --follow --format=%h default.rb | cat 573c8f5 2ccc5b8 b447bc3 # Churn Count = 3

Slide 28

Slide 28 text

Complexity

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

Complexity flog

Slide 31

Slide 31 text

Complexity $ flog default.rb => 10.8: flog total

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

Complexity $ flog foo.rb => 10.8: flog total

Slide 34

Slide 34 text

(Un)maintainable code Churn vs. Complexity

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

(Un)maintainable Code RubyCritic (github.com/whitesmith/rubycritic)

Slide 38

Slide 38 text

(Un)maintainable Code $ gem install rubycritic

Slide 39

Slide 39 text

(Un)maintainable Code $ rubycritic

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

GPA Pie Graph Complexity (flog) Code Smells (reek)

Slide 43

Slide 43 text

RubyCritic module RubyCritic class AnalysedModule def cost smells.map(&:cost).inject(0.0, :+) + (complexity / COMPLEXITY_FACTOR) end end end

Slide 44

Slide 44 text

RubyCritic module RubyCritic class AnalysedModule def cost smells.map(&:cost).inject(0.0, :+) + # From Reek (complexity / COMPLEXITY_FACTOR) end end end

Slide 45

Slide 45 text

RubyCritic module RubyCritic class AnalysedModule def cost smells.map(&:cost).inject(0.0, :+) + # From Reek (complexity / COMPLEXITY_FACTOR) # From Flog end end end

Slide 46

Slide 46 text

Churn vs. Complexity Churn (SCM) Complexity (flog)

Slide 47

Slide 47 text

100 0 1 100_000 Complexity Churn

Slide 48

Slide 48 text

100 0 1 100_000 “Welcome to the good place.” ❤ Complexity Churn

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

100 0 1 100_000 Complexity Churn These modules are complex and are constantly changing 🤦 🤦 🤦

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Tech Debt (Ruby) 1. Code Coverage (SimpleCov) 2. (Un)maintainable Code (RubyCritic)

Slide 57

Slide 57 text

Tech Debt (JS) 1. Code Coverage (Istanbul) 2. (Un)maintainable Code (github.com/ upgradejs/upjs-plato)

Slide 58

Slide 58 text

You are here:

Slide 59

Slide 59 text

Part 2: Getting out of the tar pit

Slide 60

Slide 60 text

How can we gradually pay off technical debt?

Slide 61

Slide 61 text

Measurable Metrics over Feelings (and Personal Opinions)

Slide 62

Slide 62 text

Thank you! @etagwerker 62 ‣ github.com/whitesmith/rubycritic ‣ github.com/upgradejs/upjs-plato ‣ @OmbuLabs ‣ @FastRubyIO ‣ @JSupgrade

Slide 63

Slide 63 text

Thank you! @etagwerker 63 Thank you!

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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