# Dense Implementation

> Patterns for short code with full behavior. Use when writing new logic, replacing verbose code, or simplifying implementations. Teaches compression tactics that preserve correctness.

- Skill: `aresiddharthareddy/dense-implementation` (Agent Skill)
- Install (CLI): `npx skillmds@latest add aresiddharthareddy/dense-implementation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/aresiddharthareddy/dense-implementation/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: aresiddharthareddy (https://skillmd.com/u/aresiddharthareddy)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/aresiddharthareddy/dense-implementation

---


# Dense Implementation

## Compression tactics

Apply in order until the code is short **and** clear:

1. **Use the platform** — stdlib, framework helpers, language syntax sugar.
2. **Collapse data** — table-driven logic, lookup maps, config objects.
3. **Inline** — one-use helpers that don't clarify intent.
4. **Generalize** — one function with parameters vs near-duplicate copies.

## Before / after patterns

**Manual loop → declarative**

```python
# verbose
out = []
for x in items:
    if x.active:
        out.append(x.name.upper())
# dense
out = [x.name.upper() for x in items if x.active]
```

**Branch chain → lookup**

```typescript
// verbose: long if/else if chain on enum
// dense
const LABELS: Record<Status, string> = { ok: "OK", err: "Error" };
return LABELS[status] ?? "Unknown";
```

**Null checks → optional chaining / early return**

```javascript
// verbose: nested if (a && a.b && a.b.c)
// dense
return a?.b?.c ?? defaultVal;
```

**Repeated setup → spread / destructuring / small pipeline**

Prefer chaining over temp variables when each step is obvious.

## When NOT to compress

Stop compressing if any of these become worse:

- Error messages or debugging
- Public API contracts
- Security checks (auth, validation, SQL)
- Non-obvious business rules

Extract a **named** function when the compressed one-liner needs a comment to understand.

## Density test

For each proposed block ask:

> Can I delete a line without changing behavior?

If yes, delete it. If the block is still &gt;15 lines, look for a built-in or existing project helper first.

## Pair with

`smart-code-core` for principles, `reuse-before-create` before adding helpers.

