Conditional logic selects which instructions execute, but its value depends on readable decisions. Dense Boolean expressions and deeply nested branches can increase cognitive load, so extract meaningful decisions into clearly named methods. section 2.3.5
Name the decision
Replace a condition such as checking whether a user is active, unexpired, and authorized with a named predicate such as isEligible(user). The name turns implementation details into a readable story; extract the surrounding permission handling when the branch carries another responsibility. section 2.3.5
Table 2.1 Guidelines for splitting methods
|
Approach
|
Guideline
|
|---|---|
|
Length based
|
Split a method if it grows too long.
|
|
Responsibility based
|
Each method should have one responsibility. At a low level (actions), the scope should be narrow (e.g., validating a single field). At higher levels, responsibilities can be broader (e.g., handling the full user registration process).
|
|
Simplicity driven
|
Extract code that feels cognitively heavy, such as complex Boolean conditions or deep nesting, into clearly named methods.
|
Use length, responsibility, and simplicity as complementary guides: split overgrown methods, keep responsibilities meaningful, and extract cognitively heavy conditions or nesting. section 2.3.5
Kotlin type-based branching
Kotlin if/else can select a promotional message by testing whether a Book is digital, pocket-sized, or hardcover. Smart casts avoid explicit casts, but an additional else is needed because the branch chain is not guaranteed to be exhaustive. section 5.1.3




















