rahulsub/code-practices-plugin/naive-then-optimize
Claude Code and agent skill by rahulsub/code-practices-plugin
- community
Checking that the SKILL.md file is still in the repository.
Implement the obvious correct solution first, then optimize while preserving correctness. Use for algorithms, data transformations, and critical code paths.
Install
npx vskill@latest install rahulsub/code-practices-plugin/naive-then-optimizeSKILL.md
The same SKILL.md was published earlier as rahulsub/code-practices-plugin/naive-then-optimize.
Naive-Then-Optimize Skill
Trigger
Use when implementing algorithms, data transformations, or any code where correctness is critical.
The Insight
Karpathy: "Write the naive algorithm that is very likely correct first, then ask it to optimize it while preserving correctness."
Why This Works
- Naive implementations are easier to verify as correct
- They serve as a reference/oracle for testing optimized versions
- Optimization bugs are caught by comparing to naive version
- You might find the naive version is fast enough
Process
Step 1: Implement the Obvious Solution
Don't think about performance. Think about correctness. Write the dumbest, most straightforward code that works.
Step 2: Write Tests Against Naive Implementation
Step 3: Verify Naive Implementation Passes
Run the tests. They should all pass. If they don't, fix the naive implementation first.
Step 4: Measure Performance
Is the naive version fast enough? Profile it with realistic data.
If it's fast enough, stop here. Don't optimize code that doesn't need it.
Step 5: Optimize While Preserving Behavior
Now optimize, but keep the same tests passing:
Step 6: Property-Based Testing (Optional)
For critical code, test that naive and optimized produce same results:
When to Use This
- Algorithm implementations
- Data transformations
- Parsers
- Anything where correctness matters more than cleverness
When to Skip This
- Simple CRUD operations
- Code that's obviously correct
- When the naive version would be identical to the optimized version
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/naive-then-optimize/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rahulsub/code-practices-plugin/naive-then-optimize)