Skip to content

Instantly share code, notes, and snippets.

@bgswan
Last active May 31, 2018 14:20
Show Gist options
  • Save bgswan/88c25811a9e8b6207d8f46cb1303c216 to your computer and use it in GitHub Desktop.
Save bgswan/88c25811a9e8b6207d8f46cb1303c216 to your computer and use it in GitHub Desktop.
Software X-Rays for Ruby

Software Design X-rays

  1. Measure interest rates. Ruby code that changed most frequently in the last year. git log --format=format: --name-only --after="2017-05-18" -- "*.rb" | egrep -v '^$' | sort | uniq -c | sort -r | head -10

  2. Measure size of each file. Lines of code is a simple proxy for complexity. Just Ruby files cloc . --by-file --csv --include-lang=Ruby --quiet

  3. Combine the two into a single output of filename, change_frequency, size.

require 'csv'
require 'pathname'
require 'json'

ROOT_PATH = Pathname.new("./")

def strip_path(path)
  Pathname.new(path).relative_path_from(ROOT_PATH).to_s
end

change_frequencies = File.readlines("all_frequencies.txt").map{|line| line.strip.split(" ").reverse}.to_h; nil
sizes = CSV.readlines("all_lines.csv", headers: true, skip_blanks: true).map{|row| [strip_path(row["filename"]), row["code"]]}.to_h; nil

hotspots = change_frequencies.map {|name, changes| [name, changes.to_i, sizes[name].to_i]}; nil

hotspots.sort_by{|data| [data[1], data[2]]}.reverse.take(100).each{|l| p l}; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment