fzipp / gocyclo

Calculate cyclomatic complexities of functions in Go source code.
BSD 3-Clause "New" or "Revised" License
1.33k stars 81 forks source link

add -centile flag #55

Open hangxie opened 3 weeks ago

hangxie commented 3 weeks ago

Add this flag to show percentile.

Other thought - if gocyclo plans to support more stats features, SortAndFilter would be better split into Sort and Filter.

fzipp commented 3 weeks ago

I assume this is meant to address #54 in a more general way, since the median is the 50th percentile, or was this PR an independent initiative?

I agree that Sort and Filter should probably be separate steps/functions, but you don't have to address it in this PR. I can do that later. Sort could also use the simpler slices.Sort (since Go 1.21) nowadays.

fzipp commented 3 weeks ago

The output probably needs a label, analogous to the "Average: " label for -avg.

The question is if we need a short option as well. I'm not sure how people want to use it: Do they just want to look at the output on the command line or parse it for further processing in a pipeline?

hangxie commented 3 weeks ago

Committed a new change to have label for percentile, also include centile-short to eliminate label, I don't think the change is perfect but it works.

A couple other thoughts triggered but the new commit:

  1. maybe have a -json to output things in JSON format, it can make life easier when people want to parse output
  2. replace all *-short with a global no-label CLI parameter, this will break backward compatibility though and may have a sematic problem, like user asks for avg and 90-th percentile, without label we will have to document their sequence in output.
hangxie commented 3 weeks ago

Let me know if you want me rebase to squash to single commit.