What problem does it solve?
This Skill addresses the complexity, readability issues, and error-proneness of deeply nested conditional logic (if/else statements). It provides techniques to flatten control flow, making code easier to understand, maintain, and less susceptible to bugs.
Core Features & Use Cases
- Nesting Depth Limit: Enforces keeping conditional nesting under 3 levels to improve readability and reduce cognitive load.
- Early Returns (Guard Clauses): Guides you to handle error or edge cases at the beginning of a function, reducing indentation for the main logic.
- Table-Driven Methods: Encourages encoding complex business rules as data in tables, making logic more declarative and easier to modify.
- Combined Conditions: Shows how to flatten nested
if statements by combining conditions into a single if or elif chain.
- Use Case: Instead of deeply nested
if is_vip: if order_amount > 1000: return 0.20, this skill guides you to use a table-driven approach or combined conditions to clearly define discount tiers.
Quick Start
Analyze the attached Python function calculate_discount which uses nested if/else statements. Suggest how to simplify its control flow using either combined conditions or a table-driven method.