Skip to content

Commit df57cdf

Browse files
authored
Update AV1500: Methods should not exceed 15 statements (#359)
1 parent 26a150c commit df57cdf

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

_rules/1500.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
---
22
rule_id: 1500
33
rule_category: maintainability
4-
title: Methods should not exceed 7 statements
4+
title: Methods should not exceed 15 statements
55
severity: 1
66
---
7-
A method that requires more than 7 statements is simply doing too much or has too many responsibilities. It also requires the human mind to analyze the exact statements to understand what the code is doing. Break it down into multiple small and focused methods with self-explaining names, but make sure the high-level algorithm is still clear.
7+
A method that requires more than 15 statements is simply doing too much or has too many responsibilities. It also requires the human mind to analyze the exact statements to understand what the code is doing. Break it down into multiple small and focused methods with self-explaining names, but make sure the high-level algorithm is still clear.
8+
9+
Also ensure that each method operates at a **single level of abstraction**. Mixing high-level functional calls (the "what") with low-level implementation details (the "how") in the same method makes it harder to understand the intent of the code.
10+
11+
```csharp
12+
// Avoid: mixing abstraction levels in the same method
13+
void ProcessOrder(Order order)
14+
{
15+
if (IsPremiumCustomer(order.CustomerId)) // functional; the "what"
16+
{
17+
ApplyDiscount(order);
18+
}
19+
20+
if (Regex.IsMatch(order.Email.ToUpper().Trim(), @"^[^@]+@[^@]+\.[^@]+$")) // technical; the "how"
21+
{
22+
SendConfirmation(order.Email);
23+
}
24+
}
25+
26+
// Better: extract the technical detail behind an abstraction
27+
void ProcessOrder(Order order)
28+
{
29+
if (IsPremiumCustomer(order.CustomerId))
30+
{
31+
ApplyDiscount(order);
32+
}
33+
34+
if (IsValidEmail(order.Email))
35+
{
36+
SendConfirmation(order.Email);
37+
}
38+
}
39+
```

0 commit comments

Comments
 (0)