Special Case — Code Smells Catalog Skip to content

Special Case

Also known as: Complex Conditional

Change Preventers Conditional Logic Code SmellImplementation Smell Within Class

The if-statement that handles "one weird edge case" before the real logic begins. It was a hotfix once. It was never properly refactored. Now every future reader has to hold that branch in their...

1 min read 1 source

Overview

Wake addresses the complex conditional situation as a Special Case code smell with two symptoms - a complex if statement and/or value checking before doing the actual work [1].

Causation

There was a need for a special case to handle. A hotfix that was never adequately fixed could also be the reason for the smell.

Problems

📖
Comprehensibility

The method is doing a specific task, but there is "one special case" to consider.

🧩
Increased Test Complexity

Special case has to have an extra special test.

Example

Smelly
1def parse_foo(foo: Foo) -> Goo:
2    if 'zoo' in foo.sample_attribute:
3        ...
4        ...
5        ...
6
7    ...
8    ...
9    ...
10    ...
PYTHON

Exceptions

Recursive methods always have to have a base case to stop the recursion.

---

Refactoring

  • Consolidate Conditional Expression
  • Replace Conditional with Polymorphism
  • Introduce Null Object
  • Replace Exception with Test

Sources

Browse All 56 Smells