Langsung ke konten
Skillpedia
Pemrograman umum107k Β· #765

code-simplification

Fungsinya

Alat ini membantu membuat kode program lebih mudah dibaca dan dipahami. Alat ini meningkatkan kejelasan tanpa mengubah apa yang dilakukan kode.

Kapan dipakai

  • βœ“Saat kode sudah berjalan tetapi sulit dibaca.
  • βœ“Saat meninjau kode yang terlalu rumit.
  • βœ“Saat menemukan logika yang sangat kompleks atau nama yang tidak jelas.

Link skill

https://github.com/addyosmani/agent-skills/blob/main/skills/code-simplification/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/addyosmani/agent-skills/blob/main/skills/code-simplification/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œSederhanakan kode ini agar lebih mudah dipahami:”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Alat ini menganalisis kode dan mencari cara untuk membuatnya lebih lugas, misalnya dengan menggunakan nama yang lebih baik atau menata ulang logika. Alat ini memastikan kode tetap berfungsi persis seperti sebelumnya.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Code Simplification

Inspired by the Claude Code Simplifier plugin. Adapted here as a model-agnostic, process-driven skill for any AI coding agent.

Overview

Simplify code by reducing complexity while preserving exact behavior. The goal is not fewer lines β€” it's code that is easier to read, understand, modify, and debug. Every simplification must pass a simple test: "Would a new team member understand this faster than the original?"

When to Use

  • After a feature is working and tests pass, but the implementation feels heavier than it needs to be
  • During code review when readability or complexity issues are flagged
  • When you encounter deeply nested logic, long functions, or unclear names
  • When refactoring code written under time pressure
  • When consolidating related logic scattered across files
  • After merging changes that introduced duplication or inconsistency

When NOT to use:

  • Code is already clean and readable β€” don't simplify for the sake of it
  • You don't understand what the code does yet β€” comprehend before you simplify
  • The code is performance-critical and the "simpler" version would be measurably slower
  • You're about to rewrite the module entirely β€” simplifying throwaway code wastes effort

The Five Principles

1. Preserve Behavior Exactly

Don't change what the code does β€” only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a simplification preserves behavior, don't make it.

ASK BEFORE EVERY CHANGE:
β†’ Does this produce the same output for every input?
β†’ Does this maintain the same error behavior?
β†’ Does this preserve the same side effects and ordering?
β†’ Do all existing tests still pass without modification?

2. Follow Project Conventions

Simplification means making code more consistent with the codebase, not imposing external preferences. Before simplifying:

1. Read CLAUDE.md / project conventions
2. Study how neighboring code handles similar patterns
3. Match the project's style for:
   - Import ordering and module system
   - Function declaration style
   - Naming conventions
   - Error handling patterns
   - Type annotation depth

Simplification that breaks project consistency is not simplification β€” it's churn.

3. Prefer Clarity Over Cleverness

Explicit code is better than compact code when the compact version requires a mental pause to parse.

// UNCLEAR: Dense ternary chain
const label = isNew ? 'New' : isUpdated ? 'Updated' : isArchived ? 'Archived' : 'Active';

// CLEAR: Readable mapping
function getStatusLabel(item: Item): string {
  if (item.isNew) return 'New';
  if (item.isUpdated) return 'Updated';
  if (item.isArchived) return 'Archived';
  return 'Active';
}
// UNCLEAR: Chained reduces with inline logic
const result = items.reduce((acc, item) => ({
  ...acc,
  [item.id]: { ...acc[item.id], count: (acc[item.id]?.count ?? 0) + 1 }
}), {});

// CLEAR: Named intermediate step
const countById = new Map<string, number>();
for (const item of items) {
  countById.set(item.id, (countById.get(item.id) ?? 0) + 1);
}

4. Maintain Balance

Simplification has a failure mode: over-simplification. Watch for these traps:

  • Inlining too aggressively β€” removing a helper that gave a concept a name makes the call site harder to read
  • Combining unrelated logic β€” two simple functions merged into one complex function is not simpler
  • Removing "unnecessary" abstraction β€” some abstractions exist for extensibility or testability, not complexity
  • Optimizing for line count β€” fewer lines is not the goal; easier comprehension is

5. Scope to What Changed

Default to simplifying recently modified code. Avoid drive-by refactors of unrelated code unless explicitly asked to broaden scope. Unscoped simplification creates noise in diffs and risks unintended regressions.

The Simplification Process

Step 1: Understand Before Touching (Chesterton's Fence)

Before changing or removing anything, understand why it exists. This is Chesterton's Fence: if you see a fence across a road and don't understand why it's there, don't tear it down. First understand the reason, then decide if the reason still applies.

BEFORE SIMPLIFYING, ANSWER:
- What is this code's responsibility?

…
Pertanyaan umum

Apakah ini mengubah cara kerja kode?

Tidak. Tujuannya hanya untuk meningkatkan kejelasan. Kode akan melakukan hal yang sama persis seperti sebelumnya.

Apakah saya perlu bisa memrogram untuk memakainya?

Akan membantu jika Anda memiliki pemahaman dasar tentang pemrograman untuk mengerti apa yang dilakukan kode, tetapi alat ini dirancang untuk menyederhanakan sehingga lebih mudah diakses.

Bisakah saya memakainya untuk memperpendek kode?

Fokus utamanya adalah kejelasan dan kemudahan dipahami, bukan mengurangi jumlah baris. Terkadang, kode yang sedikit lebih panjang justru lebih mudah dibaca.

Detail

Deskripsi asli dari pembuat

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

repo: addyosmani/agent-skills

Popularitas

Bintang GitHub
107k
Peringkat
#765
Lisensi
MIT
Diperbarui
13/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa