Spec driven development means writing a short, testable specification before you write the code, then letting that spec guide every step. The habit most people get wrong is treating the spec as a one-time document; it is a living agreement that you update as you learn, and it works best when it is small enough to read in one sitting.
What Does Spec Driven Development Actually Look Like?
You start with a plain-language description of what the feature should do, written before any code. It includes the inputs, the outputs, and the edge cases you care about. Then you write the code to match that spec, and you test against it.
The spec is not a design document. It is a compact contract between you and your future self (or your team). It answers three questions: What is this for? What should it do? What should it not do?
How Long Should a Spec Be?
A good spec is usually 1 to 3 pages of plain text, or about 200 to 600 words. If it is longer, you are writing design documentation, not a spec. If it is shorter than a paragraph, you are probably skipping important details.
The length matters because a spec you can read in five minutes is a spec you will actually use. A 20-page document gets ignored. Keep it short enough that you can re-read it before every coding session.
What Are the Core Habits to Build?
There are five habits that make spec driven development work in daily practice:
- Write the spec first. Before opening your editor, write the spec in a plain text file or a comment at the top of the test file. It can be as simple as a few bullet points.
- Write a test that fails. Translate the spec into a test that fails because the feature does not exist yet. This test is your executable spec.
- Implement the smallest thing that makes the test pass. Do not add extra features. Do not refactor unrelated code. Just make the test green.
- Update the spec when you learn something. If you discover a new edge case or a simpler approach, edit the spec before you edit the code. The spec stays current.
- Review the spec before you call it done. Re-read the spec and check that every line is covered by a test. If something is not covered, add a test.
These habits feel slow at first. They are not. They save time because you catch misunderstandings early, before you have written hundreds of lines of code in the wrong direction.
How Do You Write a Spec That Is Actually Useful?
Use a simple template. It does not need to be fancy. Write these sections:
- Purpose: One sentence on why this feature exists.
- Inputs: What data does it take? What format?
- Outputs: What does it return or do?
- Edge cases: What happens with empty input, missing data, or unusual values?
- Out of scope: What are you deliberately not doing?
For example, a spec for a function that greets a user might look like this:
Purpose: Return a greeting message for a given name.
Inputs: A string name, may be empty.
Outputs: A string “Hello, {name}!” if name is not empty, otherwise “Hello, world!”.
Edge cases: Empty name, name with spaces, name with special characters.
Out of scope: No localization, no personalization.
That is 50 words. It is enough to write a test and implement the function correctly.
What Changes the Time It Takes?
The main factor is how familiar you are with the codebase. If you are working in a new codebase, the spec writing will take longer because you need to understand the existing patterns. In a familiar codebase, a spec can take 5 to 10 minutes to write.
The size of the feature also matters. A small bug fix might only need a one-line spec. A new API endpoint might need a page. The rule is: if you cannot write the spec in under 15 minutes, you do not understand the problem well enough to start coding.
Another factor is how often you update the spec. If you treat the spec as fixed, you will resist necessary changes. If you update it every time you learn something, it stays accurate and useful.
How Do You Know If You Are Doing It Right?
You are doing it right if you can answer these three questions at any moment:
- What is the current spec for the feature you are working on?
- Does the test suite fully cover that spec?
- Does the code match the spec, not the other way around?
If you cannot answer the first question, you have not written a spec. If the answer to the second is no, you have untested behavior. If the answer to the third is no, you have drifted from the spec and need to decide which one to change.
A common sign you are doing it wrong is when you write the spec after the code. That is not spec driven development; it is documentation after the fact. The spec must come first, even if only by five minutes.
What If the Spec Changes Mid-Implementation?
That is normal. Requirements change. The key is to update the spec first, then update the code. Do not let the code drift and then try to remember what the spec said.
When the spec changes, do these steps in order:
- Edit the spec to reflect the new requirement.
- Update or add tests to cover the new behavior.
- Run the tests and watch them fail (because the code has not changed yet).
- Update the code to make the tests pass.
- Re-read the spec to confirm it is still accurate.
This order keeps the spec as the source of truth. It also prevents you from making changes to the code that are not reflected in the spec, which is how technical debt starts.
How Does This Fit Into a Calm Daily Routine?
Spec driven development is a habit of clarity. It forces you to think before you act, which reduces the anxiety of starting a complex task. When you know exactly what you are building and why, you can work with focus instead of guessing.
If you are new to this, start with one small task. Write a spec for it, even if it feels like overkill. Notice how much clearer your thinking becomes. Then try it on a slightly larger task. Over time, it becomes a natural way to approach any coding problem.
The habit also helps with collaboration. When you share a spec with a teammate, you both know what “done” means. That reduces friction and makes code reviews faster.
What If I Work Alone?
Specs still help. They act as a record of your decisions. When you come back to a project after a week away, the spec tells you what you were thinking. That is especially valuable for side projects and open source work.
What If My Team Does Not Use Specs?
You can still use them personally. Write a spec for your own work before you start. Share it with your team if they are open to it, or keep it in a private file. The benefit is mostly for you: clearer thinking and fewer mistakes.
Is This the Same as Test-Driven Development?
Not exactly. Test-driven development (TDD) is a specific practice where you write a failing test before the code. Spec driven development is broader: it is about writing a specification before the code. TDD is one way to make the spec executable. You can do spec driven development without TDD, but they work well together.
If you already practice TDD, you are halfway there. The spec adds the “why” and the edge cases that a test alone does not capture.
What Should You Do Next?
Pick one small feature or bug fix you are about to work on. Before you write any code, write a spec using the template above. Keep it under 200 words. Then write a test that fails, and implement the feature. When you finish, re-read the spec and update it if needed.
That is the whole habit. It takes ten extra minutes on the first try, and it will save you hours of rework. The more you do it, the faster it becomes, until it is just how you work.
Related
- Purpose Driven Productivity Tips
- Journaling Questions for Personal Development
- How to Track Your AA Habits
General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more
Spotted an error? Tell us and we will correct it (corrections policy).