cognitive-load

Restructure complex code logic to reduce mental effort for readers.

Updated Mar 22, 2018
One-click install
npx skills add https://github.com/tnunamak/dotfiles --skill cognitive-load-tnunamak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cognitive-load
Source: https://github.com/tnunamak/dotfiles/tree/main/ai/skills/local/cognitive-load
Command: npx skills add https://github.com/tnunamak/dotfiles --skill cognitive-load-tnunamak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It reduces mental strain when reading and maintaining code by preventing overly complex logic and shallow, hard-to-follow abstractions.

Core Features & Use Cases

  • Simplify decision logic: Break complex conditions into descriptive intermediate variables and improve readability with early returns instead of deeply nested branches.
  • Improve structure and naming: Use self-descriptive values and avoid custom mappings that require extra memorization.
  • Refactor for working-memory limits: Prefer fewer, clearer layers of responsibility and avoid unnecessary abstraction that forces readers to track too many concepts at once.
  • Use Case: Refactoring a tangled feature flag condition and nested if/else blocks into a sequence of named booleans that reads linearly for reviewers.

Quick Start

Use cognitive-load to rewrite the function so the logic is flatter, conditions are expressed via meaningful intermediate variables, and any necessary comments explain the motivation rather than restating the obvious.

Frequently Asked Questions about cognitive-load

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce cognitive load when reading complex nested code?

You can reduce cognitive load by applying early returns to flatten nested branches and replacing complex conditions with descriptive intermediate variables. This allows readers to process logic linearly rather than tracking multiple nested states.

What is the best way to refactor tangled if/else blocks for code review?

The best way to refactor tangled if/else blocks is to convert them into a sequence of named boolean variables. This expresses conditions via meaningful intermediate values, making the decision logic readable and self-descriptive for reviewers without extra memorization.

Why does shallow abstraction make code harder to maintain?

Shallow abstraction makes code harder to maintain because it forces readers to track too many concepts at once, increasing working-memory load. Preferring fewer, clearer layers of responsibility prevents unnecessary abstraction that obscures the actual logic flow.

Can I use this approach to simplify feature flag conditional logic?

Yes, you can simplify feature flag conditional logic by extracting tangled conditions into named booleans. This refactoring approach transforms complex flag evaluations into a linear sequence that is straightforward for reviewers to read and understand.

When should I not use intermediate variables during refactoring?

You should avoid intermediate variables when they require custom mappings that force extra memorization rather than providing self-descriptive values. If the variables do not clarify the motivation behind the logic or reduce nesting, they only add unnecessary layers.