What problem does it solve?
This Skill solves the problem of code that's hard to understand and maintain due to variables declared far from where they're used, with unnecessarily wide scope and long lifetimes.
Core Features & Use Cases
- Scope Minimization: Declare variables in the smallest possible scope, from block to function to class level.
- Live Time Reduction: Initialize variables close to first use to minimize the window where they could be incorrectly modified.
- Use Case: When reviewing a pull request where variables are declared at the top of a function but used 50 lines later, apply these techniques to reduce mental load and prevent errors.
Quick Start
Review this function and localize all variables by declaring them in the smallest possible scope and initializing close to first use.
def process_data():
index = 0
total = 0
done = False
result = []
# ... 30 lines of other code ...
while index < count:
index += 1
while not done:
if total > threshold:
done = True
result.append(final_value)
return result