AgentSkillsCN

maintaining-design-quality

适用于修改现有代码、修复缺陷,或扩展功能时使用。

SKILL.md
--- frontmatter
name: maintaining-design-quality
description: Use when modifying existing code, fixing bugs, or extending features.

Maintain Design Quality

Overview

Core Principle: If you're not making the design better, you're probably making it worse. Working code is not a high enough standard.

Discipline Requirement: Every modification is an opportunity to improve or degrade design. Resist quick fixes. Ask whether the current design is still optimal given the change you need to make.

Zero Tolerance: There is no acceptable threshold for making design worse. Even "small" compromises accumulate invisibly—dozens of tactical decisions compound into unmaintainable systems. Each change must improve or maintain design, never degrade it.

When to Use

  • Fixing bugs in existing code
  • Adding features to existing modules
  • Extending or modifying existing behavior
  • Working under time pressure ("quick fix")
  • Touching legacy code
  • User says: "fix bug", "modify", "extend", "quick change", "add to existing"

When NOT to Use

  • Creating new modules from scratch (see: designing-deep-modules)
  • Evaluating code quality (see: reviewing-module-design)
  • Simplifying complex code (see: simplifying-complexity)
  • Improving clarity only (see: improving-code-clarity)
  • Performance optimization (see: optimizing-critical-paths)

Urgency Tiers

Not all changes need equal analysis. Match effort to impact:

TierExamplesRequired Analysis
TrivialTypo fixes, whitespace, comment correctionsNone—just do it
MinorBug fix <5 lines, config tweak, dependency bumpQuick check: does this fit cleanly?
StandardNew feature, refactoring, multi-file changeFull workflow: STOP-ASK-DECIDE-VERIFY
EmergencyProduction down, security breach, data lossMinimal fix + TODO + 24hr follow-up

Emergency Bypass Criteria

Skip the normal workflow ONLY when ALL of these conditions are true:

  1. Production is down RIGHT NOW (not "might break soon")
  2. Users are actively impacted, security breach in progress, OR data loss occurring
  3. The fix is minimal (rollback or single-line change)
  4. You commit to returning for proper implementation within 24 hours

Emergency does NOT mean:

  • "Demo in 30 minutes" — That's planning failure
  • "CEO is asking" — Authority pressure ≠ emergency
  • "Team is blocked" — They can wait for you to think
  • "We need this fast" — Speed pressure is when discipline matters MOST

Emergency DOES mean:

  • Production is down and users are impacted NOW
  • Security vulnerability being exploited
  • Data corruption or loss occurring

Strategic Modification Workflow

code
BEFORE making any change to existing code:

1. RESIST the temptation to make a quick fix

2. ASK: "Is the current system design still the best one,
   given the change I need to make?"

3. IF NO: Refactor so you end up with the best possible design
   Goal: After this change, the system should have the structure
   it would have had if designed from the start with this in mind

4. IF YES: Make the change within the existing design
   But verify: does your change fit cleanly?

5. BEFORE COMMIT: Scan all changes to verify documentation reflects them

The Investment Mindset

ApproachShort-TermLong-Term
Tactical10-20% fasterPermanently slower (20%+ productivity loss)
Strategic10-20% slowerBenefits in months; eventually free

Recommended investment: About 10-20% of development time on design improvements.

Why Strategic Wins

code
Tactical path:
- Each "quick fix" adds small complexity
- Complexities accumulate (dozens/hundreds of small things)
- Eventually: system is hard to understand and modify
- Result: development slows permanently

Strategic path:
- Each change improves or maintains design
- Past investments save time for future investments
- Eventually: strategic investments become FREE
- Result: development accelerates over time

Design Evolution Principle

A system's design cannot be conceived correctly at the outset. The design of a mature system is determined more by changes made during evolution than by initial conception.

Implication: Every modification matters. Your changes ARE the design.


When Refactoring Seems Impractical

Even under tight deadlines, ask:

code
"Is this the best I can possibly do to create a clean system design,
given my current constraints?"
If...Then...
Large refactoring is impracticalLook for alternatives that are almost as clean but faster
Cannot do proper cleanup nowCreate accountability plan (see below)
Refactoring creates incompatibilitiesSeek middle-ground solutions

Never acceptable: Making the design worse without a plan to fix it.

Accountability for Deferred Refactoring

If you defer refactoring, it MUST be tracked:

code
1. CREATE a ticket/issue with specific scope
2. TIMEBOX: Must be addressed within 2 sprints (or equivalent)
3. ADD a code comment: // TODO(YYYY-MM-DD): [ticket-id] - [what needs fixing]
4. ESCALATE if 3+ deferrals exist in same area → refactoring becomes MANDATORY

"I'll do it later" without these steps = you won't do it.


When NOT to Refactor

Refactoring is not always the right choice:

ScenarioWhy Refactoring HurtsWhat to Do Instead
Chesterton's Fence codeLooks bad but handles subtle edge casesInvestigate WHY before changing
Performance-critical pathsClean abstractions add overheadDocument why it's intentionally ugly
Regulatory/audited codeChanges trigger expensive re-certificationGet explicit approval first
Legacy with no testsRefactoring without tests is dangerousAdd tests first, or freeze
Code with external quirk dependenciesOther systems rely on undocumented behaviorCoordinate with dependents
Near end-of-life systemsInvesting in dying code is wasteDocument, don't improve
During incident responseChanging more increases blast radiusMinimal fix only
When you don't understand domain"Better design" reflects misunderstandingLearn first, refactor later

Key question: Do I understand WHY the code is the way it is?

If no → investigate before refactoring.


Red Flags

Red FlagSymptomWhat It Signals
Quick Fix Mentality"Just make it work for now"Tactical programming—design will degrade
Complexity CreepAdding special cases, conditionals, dependenciesDesign is getting worse, not better
Patch StackingWorkarounds on top of workaroundsTechnical debt accumulating
Tactical TornadoVery fast developer leaving messesOthers will pay for their speed
Stale CommentsComments no longer match codeTrust erosion; documentation debt
Deferred Cleanup"We'll refactor later"Later never comes; delay becomes permanent

Anti-Rationalization Table

Classic Rationalizations

Tempting ShortcutWhy It Feels RightWhy It's Wrong
"Just make it work"Faster nowCreates technical debt forever; 20%+ productivity loss
"Don't touch working code"Risk aversePrevents improvement; design decays anyway
"We'll refactor later"Deferred painLater never comes; there's always another crunch
"This is just a quick fix"Scope limitingQuick fixes accumulate; complexity is incremental
"I don't have time"Deadline pressure10-20% investment now saves more later
"It's not that bad"Normalizing decayEach small compromise adds up to major complexity
"Someone else will clean it up"DelegationYou are that someone; it never happens

Responsibility-Avoidance Rationalizations

Tempting ShortcutWhy It Feels RightWhy It's Wrong
"I'm not the owner of this module"Not my responsibilityIf you're touching it, you're responsible for it
"The original author did it this way"Appeal to authorityOriginal author might have been wrong, or context changed
"This matches the existing pattern"ConsistencyConsistently following a bad pattern spreads the problem
"I'm just copying what's in the other file"Following exampleYou're spreading bad patterns across the codebase

"It Doesn't Count" Rationalizations

Tempting ShortcutWhy It Feels RightWhy It's Wrong
"This is temporary/experimental code"It's throwawayNothing is as permanent as temporary code
"The tests pass"Correctness verifiedPassing tests ≠ good design; tests check behavior, not quality
"I'll document the tech debt"I'm being responsibleDocumentation is not remediation; debt still accrues interest
"This is behind a feature flag"It's isolatedFeature flags don't quarantine design rot
"This is just a config change"It's not real codeConfig is code; complexity hides there too
"This is just glue code"It's boilerplateAll code deserves design thought

Misapplied Principles

Tempting ShortcutWhy It Feels RightWhy It's Wrong
"Refactoring violates YAGNI"Don't over-engineerYAGNI applies to features, not code quality
"The code is already so bad my change can't make it worse"PragmatismNihilistic surrender; you can always make things worse
"The PR is already too big"Keep PRs smallSplit the PR; don't use size to excuse quality
"I need to ship to get feedback first"Iterate fastDesign debt accrues before feedback arrives

Comment Maintenance

When modifying code, keep comments synchronized:

RuleWhy
Position comments close to code they describeDevelopers see them when modifying
Avoid duplicating documentationOne source of truth; easier to maintain
Document each decision exactly onceFind the single most obvious place
Scan all changes before commitCatch stale comments early
Use higher-level comments when possibleResilient to minor code changes

Technical Debt Reality

MythReality
"We'll pay it back"Most technical debt is never fully repaid
"It's a fair trade"Amount paid back exceeds amount borrowed
"Just this once"Once you start, it's difficult to change
"Everyone does it"Complexity accumulates rapidly if everyone programs tactically

Quick Reference

code
EVERY TIME you modify existing code:

1. STOP - Resist the quick fix temptation
2. ASK - "Is this design still optimal for what I need?"
3. DECIDE:
   - Design is optimal? Make change cleanly
   - Design needs work? Refactor first
   - Can't refactor now? Plan when you will
4. VERIFY - Comments updated? Design improved or maintained?
5. COMMIT - Only when design is better or at least not worse

THE RULE:
"If you're not making the design better, you're probably making it worse."

INVESTMENT MATH:
- 10-20% slower now → faster forever
- "Quick fix" now → 20%+ slower forever

References: aposd-foundations for complexity symptoms