same-results-less-code

v2026.09.24

Same behaviour in fewer, clearer lines — covers the judgment gaps that linters cannot catch (reinvention, wrong frame, hidden duplication, derived state, procedural rebuilds, speculative generality, defensive excess, type-system underuse). Trigger when reviewing, refactoring, or simplifying code — and even when the user doesn't explicitly ask for "simplification" but is reviewing code, refactoring, or asking "is there a shorter way to write this?". Complements knip/eslint/ruff/tsc by focusing on the conceptual modelling layer those tools cannot see.

GitHub
Install command
npx skhub add pproenca/same-results-less-code
Markdown
SKILL.md

Community Refactoring Best Practices: Same Results, Less Code

Code-review and refactoring guide focused on the parts of code volume that come from judgment and modelling gaps — wrong abstraction choices, hidden semantic duplication, defensive habits, premature generality. This skill deliberately skips what linters and tools like knip, eslint, ruff, tsc --noUnusedLocals, or formatters already catch. It is the second pass: after the mechanical cleanup, what remains?

Core Principles

  1. Preserve behaviour. Every transformation must produce identical observable behaviour — same outputs, same errors, same side effects, same API surface.
  2. Earlier mistakes cascade. A wrong frame multiplies into wrong shapes, which multiply into duplicate logic. Optimise from the top of the lifecycle.
  3. Explain why, not just what. Each rule explains the cost of the anti-pattern so judgment can transfer to novel cases.
  4. Quantify where possible. Prefer "eliminates N lines / prevents X bug class" over "cleaner."
  5. Don't over-refactor. Rule of three: extract abstractions when duplication has actually appeared three times, not in anticipation.

When to Apply

Use this skill when:

  • Reviewing a PR for "could this be simpler?" (the question linters can't answer)
  • Refactoring code that has grown in volume without growing in capability
  • Auditing a module that "feels heavy" — many flags, many layers, many checks
  • Onboarding to an unfamiliar codebase and trying to spot the parts that are accidental volume vs essential complexity
  • Designing a new module and wanting to avoid the common over-abstraction traps
  • Working alongside knip / eslint / ruff and wanting the layer of judgment those tools can't supply

Don't use this skill for:

  • Mechanical cleanup that a linter or formatter already does (unused imports, dead exports, style) — use knip, eslint, ruff, or prettier/black instead.
  • Algorithmic complexity / performance tuning — use complexity-optimizer for that.
  • General cleanup of recently modified code regardless of mental-model gaps — use code-simplifier.

Rule Categories by Priority

#CategoryPrefixImpactRulesGist
1Reinventionreinvent-CRITICAL5You wrote what the platform/stdlib already provides
2Wrong Frameframe-CRITICAL5Wrong abstraction shape — class where a function fits, manager nouns, OO over data
3Hidden Duplicationdup-HIGH5Semantic copies hiding behind syntactic differences
4Derived State Storedderive-HIGH5Storing what should be computed
5Procedural Rebuildsproc-MEDIUM-HIGH5Imperative reimplementation of declarative concepts
6Speculative Generalityspec-MEDIUM5Generality built for a second user who never arrived
7Defensive Excessdefense-MEDIUM4Checks for states the type/flow already rules out
8Type System Underusetypes-LOW-MEDIUM6Runtime guards that should be types

Quick Reference

1. Reinvention (CRITICAL)

2. Wrong Frame (CRITICAL)

3. Hidden Duplication (HIGH)

4. Derived State Stored (HIGH)

5. Procedural Rebuilds (MEDIUM-HIGH)

6. Speculative Generality (MEDIUM)

7. Defensive Excess (MEDIUM)

8. Type System Underuse (LOW-MEDIUM)

How to Apply (Workflow)

When asked to review or refactor code with this skill:

  1. Run the mechanical pass first. knip/eslint/ruff/tsc --noUnusedLocals will catch dead code, unused imports, style. Don't duplicate that work here.
  2. Read the file or PR for intent. Ask: what is this code trying to do? The judgment skill is recognising when the implementation overshoots the intent.
  3. Walk the categories in priority order.
  4. Propose minimal-diff transformations. Each rule shows incorrect → correct as a tight diff; preserve that property in suggestions.
  5. Verify behaviour. Outputs, errors, and side effects must be identical. Tests must still pass.
  6. Don't bundle unrelated changes. Each transformation should map to one category. Mixing them makes the change hard to review.

When NOT to Apply

  • Code is younger than the rule of three (one or two duplicates) — extracting is premature.
  • The pattern is genuinely a known exception (see each rule's "When NOT to use this pattern" section).
  • The refactor would be a large, risky rewrite without a clear test safety net — propose, don't execute.
  • Performance-critical hot paths where the "simpler" form has measurable cost — measure first.

Reference Files

FileDescription
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information

Related Skills

  • code-simplifier — Mechanical simplification (naming, dead code, nesting). Complementary first pass.
  • complexity-optimizer — Algorithmic/performance complexity. Different axis.
  • refactor — General-purpose refactoring workflow.
  • clean-code — Broader clean-code principles. This skill is the narrower, judgment-focused subset.
Discovery
Tags

No tags published for this skill.

Version
Latest version metadata

Version

v2026.09.24

Published

Sep 24, 2026

Category

Uncategorized

License

MIT

Source path

skills/.experimental/same-results-less-code

Default branch

master

Latest commit

cf93c57

Tree SHA

afbb575