GithubHelp home page GithubHelp logo

Explanation of values about complexity HOT 1 CLOSED

thoughtbot avatar thoughtbot commented on June 14, 2024
Explanation of values

from complexity.

Comments (1)

joshuaclayton avatar joshuaclayton commented on June 14, 2024

@pylipp that's a great question and one that I don't quite know the answer to yet. The algorithm we use is one very quickly hacked together that correlated with what we were seeing generally from rubycritic from one of our moderately large internal Rails codebases (~100kloc).

When I run the tool, I'm doing a numeric sort complexity | sort -n --reverse | head -n 20 to get a sense of where to focus within new codebases. There might be too strong a correlation with file length – and the algorithm can be adjusted if that's the case.

If the score of a file is < 100, it's likely it's going to be easy to grok. Again, this is an approximation tool, and not one that interprets files. I don't expect that to change anytime soon.

I did break apart scoring to use the visitor pattern as a way to encourage other algorithms/approaches be used. I would imagine this could be configurable on a per-file-type basis eventually, or score differently for files that don't "roll back up" like Haskell or Elm versus Ruby or Elixir.

The current algorithm: 7fb66a2#diff-0e83e34ba12421d41f8a2e93ca67eff995ef8511c656b50a56e45fc9167d8abe

The current scoring structure that uses the scoring visitor:

pub fn score<V: ScoreVisitor>(visitor: &mut V, input: &[usize]) -> f32 {
let line_length = input.len();
visitor.visit_line_length(line_length);
let mut previous_line_whitespace = None;
for current_whitespace in input {
match previous_line_whitespace {
None => {
visitor.visit_first_line(*current_whitespace);
}
Some(previous_whitespace) => {
if previous_whitespace < *current_whitespace {
visitor.visit_indent(*current_whitespace);
} else if previous_whitespace == *current_whitespace {
visitor.visit_same(*current_whitespace);
} else {
visitor.visit_dedent(*current_whitespace);
}
}
}
previous_line_whitespace = Some(*current_whitespace);
}
visitor.score()
}

The current written-out way to read the current scoring algorithm: 7fb66a2#diff-12b7e19d8f3e5e1cf0dbe75aff102362944bb1cf00c4634b2aec22fe393c16e9R115-R133

from complexity.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.