AI Interview Series 14: What’s the difference between vibe coding and spec coding?
This is a question most programmers face. Vibe Coding and Spec Coding are two distinct paradigms when programming with large language models (LLMs). The core difference is: Is your input to the AI a vague feeling or a precise specification?
1. A simple analogy: Cooking
- Vibe Coding = You tell a friend, "I want something spicy." The friend cooks a dish by intuition. You taste it and say, "A bit saltier," and they add salt. The flavor might be amazing, but a different friend would produce a completely different dish.
- Spec Coding = You write a recipe: "20g Pixian bean paste, 150g beef slices, 50g celery segments, stir-fry on high heat for 2 minutes, add 3g sugar before serving." Different chefs following the recipe produce highly consistent results.
2. Definitions
| Dimension | Vibe Coding | Spec Coding |
|---|---|---|
| Aliases | Intuition-driven coding, prompt improvisation | Specification-driven coding, documentation-first |
| Input form | "Make a good-looking login page with a tech feel" | "Login page must include email/password fields, a 'Remember me' checkbox, and a submit button; frontend uses React + Tailwind; form validation: email format, password length ≥ 8; show red error message on failure..." |
| AI usage | Conversational, iterative: give general direction → see output → refine | Engineering-like: write detailed PRD/tech spec first → AI generates code based on spec |
| Human involvement | Low: relies on AI creativity; human only judges if it "feels right" | High: human completes design/architecture first; AI mainly executes |
| Typical scenarios | Rapid prototypes, personal tools, UI exploration, creative coding | Production systems, team collaboration, code requiring maintainability/testability |
3. Workflow comparison
Vibe Coding workflow
- Vague idea: "I want to write a scraper to grab Zhihu hot topics."
- First prompt: Directly ask AI to generate code.
- Run → error → paste error → AI fixes.
- UI looks ugly → "Make that button rounder and change background to gradient blue" → AI changes.
- Missing feature → "Add a save to CSV function" → AI adds.
- Loop steps 3–5 until "it feels about right."
Spec Coding workflow
- Write specification document: Clarify input/output, data structures, error handling, performance requirements, non-functional requirements (e.g., logging, rate limiting).
- Break spec into tasks: e.g., Task 1: Implement
fetch_hot_topics()function, adhering to the API signature in the spec. - Have AI implement one task at a time: Prompt includes function signature, comments, expected test cases.
- Manual review and verification: Ensure compliance with spec; run unit tests.
- Integration and regression.
4. Pros and cons
| Feature | Vibe Coding | Spec Coding |
|---|---|---|
| Startup speed | Very fast; prototype in minutes | Slow; need to write documentation and break down tasks |
| Code quality | Low (may be redundant, inconsistent, with hidden bugs) | High (readable, testable, architecturally sound) |
| Maintainability | Poor; later developers can't understand "why it was written this way" | Good; the spec is the documentation |
| Dependence on LLM | Very high; switching models may produce completely different output | Moderate; as long as the spec is clear, different models yield similar structure |
| Debugging difficulty | Hard; you don't know where the logic came from | Easy; check against spec line by line |
| Suitability for teamwork | Almost impossible | Yes (spec serves as a communication contract) |
| Output determinism | Low; results may drift with each conversation | High; same spec produces stable output |
5. Practical advice
"At work, you don't have to choose between vibe coding and spec coding; they are used together – apply the right approach in the right scenario:
- During the exploration phase (when unsure about tech stack or UI style), use Vibe Coding to quickly validate different ideas, e.g., 'Write a card component with Tailwind to see how it looks.'
- Once the solution is confirmed, immediately switch to Spec Coding: reverse-engineer the successful prototype into a clear specification (input/output, edge cases, error handling), then have AI or a human strictly follow the spec to rewrite production-grade code.
Pure vibe mode is only suitable for one-off scripts or internal tools; for systems that need long-term maintenance and multiple users, Spec Coding is a hard requirement."
评论
暂无已展示的评论。
发表评论(匿名)