A tech lead plans a refactoring for the next quarter and has two candidates. OrderService has 514 lines of code in 46 methods and covers ordering, payment, shipping, cancellation, returns, emails and dunning. PriceCalculator has 60 lines of code and calculates tax, customer discount and rounding. The analysis with CodeCharter v1.7.0 reports 15 findings for OrderService, among them an empty catch block and class-too-large, and one for PriceCalculator:
> codecharter analyze Shop.slnx
ERROR [ErrorHandling] Empty catch block
catch (System.TimeoutException)
.\src\Shop\Ordering\OrderService.cs:181
…
INFO [Design] Class too large
Shop.Ordering.OrderService
.\src\Shop\Ordering\OrderService.cs:8
…
INFO [Design] Method has boolean flag parameter
Shop.Pricing.PriceCalculator.Tax
.\src\Shop\Pricing\PriceCalculator.cs:55
21 violations (1 error, 4 warnings, 16 infos)
By finding count, OrderService wins clearly. Two other numbers reverse the ranking: how often a class changed and how many types depend on it. The following sections collect both for this solution. The solution and its Git history are constructed for this article; the outputs come from real runs.
Code smells, size and changes
Sjøberg and colleagues had six professional developers carry out maintenance tasks on four functionally equivalent Java systems. They measured the effort per file (Quantifying the Effect of Code Smells on Maintenance Effort, IEEE TSE 2013). A model of developer, system and round, file size and the number of revisions during the tasks explained 58% of the differences in effort. When the authors added the twelve code smells they studied, the value did not rise. They conclude that smaller files and ways of working with fewer changes are more likely to reduce effort than removing smells.
In Sjøberg's study, the revisions happened during the same tasks. A different study shows that earlier changes indicate later problems. Nagappan and Ball examined Windows Server 2003 (Use of Relative Code Churn Measures to Predict System Defect Density, ICSE 2005). They measured how many lines changed in each binary between two versions and compared that with the defects reported later. When they related the changes to size, they predicted defect density well (R² 0.811). The absolute number of changed lines predicted almost nothing (R² 0.052). The study measures defects, not effort. The unit is a binary, not a class, and it counts changed lines, not commits.
Together, this supports a cautious conclusion. A finding names a place worth a closer look. For the order, size and changes count, and they count relative to each other.
Change frequency from Git
CodeCharter does not count changes per file. Git supplies the number itself, here as commits per file since November 11, 2025:
git log --since=2025-11-11 --format= --name-only -- "*.cs" | sort | uniq -c | sort -rn
23 src/Shop/Pricing/PriceCalculator.cs
1 src/Shop/Shipping/FreeShippingRule.cs
1 src/Shop/Quotes/QuoteService.cs
1 src/Shop/Ordering/OrderService.cs
1 src/Shop/Cart/CartService.cs
In PowerShell, Group-Object replaces sort and uniq and returns the same numbers:
git log --since=2025-11-11 --format= --name-only -- "*.cs" |
Group-Object | Sort-Object Count -Descending | Format-Table Count, Name
The period contains 27 commits, and 23 of them change PriceCalculator.cs. OrderService.cs changed once, for the wording of the cancellation email. Relative to size, the gap grows further: 23 commits on 60 lines of code against one commit on 514.
Git counts files, not classes. When a file holds several types, or a partial class spans several files, the team maps the numbers by hand. Squash merges combine many changes into one commit; there, git log --numstat counts more precisely because it outputs the changed lines. Formatting commits inflate both numbers. If the team imported the repository only recently or merged the history during a migration, the number says nothing, and the findings remain the better basis.
Dependents from the code graph
The code graph shows how far a change reaches. graph hubs lists the types with the most incoming edges (fan-in, shortened):
> codecharter graph hubs --top 8
Shop.Domain.OrderLine fanIn=13 fanOut=0 instability=0
Shop.Pricing.PriceCalculator fanIn=12 fanOut=3 instability=0.2
Shop.Domain.Customer fanIn=8 fanOut=1 instability=0.111
…
Shop.Ordering.OrderService fanIn=2 fanOut=11 instability=0.846
graph impact also follows dependencies across several levels. For PriceCalculator it reports 12 direct and 2 indirect dependents, among them OrderService itself. Only OrderEndpoint and StaleOrderJob use OrderService:
> codecharter graph impact OrderService
Dependents by distance (1 level(s)):
Distance 1 (2):
Shop.Api.OrderEndpoint (class) .\src\Shop\Api\OrderEndpoint.cs:6
Shop.Backoffice.StaleOrderJob (class) .\src\Shop\Backoffice\StaleOrderJob.cs:5
With 13, OrderLine has the highest fan-in in the solution and never changed during the period. Its dependents rely on a type that does not move. OrderLine therefore does not go on the list.
Ranking and refactoring
Side by side, the three numbers produce a different order than the finding count:
| Candidate | Findings | Commits since 2025-11-11 | Fan-in | Dependents (graph impact) |
|---|---|---|---|---|
OrderService |
15 | 1 | 2 | 2 |
PriceCalculator |
1 | 23 | 12 | 14 |
PriceCalculator comes first. Each of its frequent changes hits a type whose results twelve others use directly. OrderService has the most findings, but changed only once during the period, for the wording of an email.
The history itself shows what to refactor. 19 of the 23 commits on PriceCalculator.cs changed only lines of the tax rate table. The refactoring moves the table into a class TaxRateTable that PriceCalculator receives through its constructor. The diff covers two files with 35 inserted and 28 deleted lines. graph diff then compares the graph with main:
> codecharter graph diff --base main
Nodes: 26 -> 27 (+1/-0). Edges: 77 -> 79 (+2/-0/~0).
Added nodes (1):
+ Shop.Pricing.TaxRateTable (class)
Added edges (2):
+ Shop.Pricing.PriceCalculator -Uses-> Shop.Pricing.TaxRateTable (weight=1)
+ Shop.Pricing.PriceCalculator -Calls-> Shop.Pricing.TaxRateTable (weight=1)
Coupling changes (2):
PriceCalculator fanIn 12 -> 12 fanOut 3 -> 4
TaxRateTable fanIn 0 -> 1 fanOut 0 -> 0
The refactoring adds two edges from PriceCalculator to TaxRateTable and removes none. This does not shrink the reach of a change: graph impact TaxRateTable reports one direct and 14 indirect dependents. The refactoring separates the frequently changed data from the pricing logic. From now on, a new tax rate changes a table without logic, and the file with discount and rounding, which twelve types use, stays unchanged. After the next quarter, the team checks whether that happens with git rev-list --count --since=… HEAD -- <file> for both files.
Planned changes
The history stands in for the expected need for change only as long as no plan exists. If a feature that touches OrderService is due next quarter, the plan takes precedence. In the example, partial deliveries are coming, and a first draft adds a method ShipPartially that repeats validation, loading, saving and the shipping email from Ship. Sas, Avgeriou and Uyumaz studied architecture smells in nine industrial C/C++ projects. In one of their twelve interviews, an interviewee reports that the team had to refactor a tightly coupled component before a new feature.
For this quarter, OrderService then comes first. The team refactors the part the feature touches, before or together with the feature. The article on refactoring large C# classes shows how to extract responsibilities from a large class. From the outside, this is cheap, because only two types depend on the class. On the inside, the example has no tests at all, so the first tests for shipping and emails belong in the same plan. PriceCalculator stays on the list, because its refactoring is small: two files, 63 changed lines.
In the feature's pull request, the diff analysis reports the findings of OrderService only with --diff-context. Without the option, it stays green and only states their number:
> codecharter analyze Shop.slnx --git-ref main..HEAD
Note: 15 finding(s) in diff-touched files fall outside the changed lines (e.g. class- or namespace-level findings) and were NOT gated. Re-run with --diff-context to report them.
No violations found.
The same call with --diff-context reports the 15 findings and ends with exit code 1, because the empty catch block is an error finding. If the PR gate runs this way, the feature PR turns red because of a finding that was already in the class before. The team then decides in the PR whether to fix the old finding along with the feature. Both runs show v1.7.0. In versions after v1.7.1, --git-ref without --diff-context no longer only counts these findings: those at or above --fail-on (every one when --fail-on is not given) fail the run and are named on stderr by severity and rule; --diff-context still reports all of them, and --no-diff-context-gate restores the count-only behaviour (analyze documentation). The call without options above then also ends with exit 1.