Erwin Salas

Articles & resources

How to Teach Python Using Spec-Driven Development

Leer en español ↗
About this translation

Original publication dates and historical context are preserved. Images, embedded media, source documents and code examples remain in their original language.

 

Programming education · Methodology

Learning Python usually starts the same way: variables, data types, conditionals, loops, functions, and, after several sessions, a practical project. The problem is that this approach forces students to learn the syntax first and only later understand what it is for.

An interesting alternative is to reverse the process through Spec-Driven Development (SDD) or development guided by specifications.

The sequence

Problem → Specification → Code → Test → Correction

Instead of starting by asking “How does a if work in Python?”, we start by asking:

What exactly should the program do?

This seemingly small change can make learning programming much more intuitive, especially for people with no previous background in software development.

What is Spec-Driven Development?

Spec-Driven Development proposes having a sufficiently clear specification of the system's expected behavior before writing code. A simple specification should answer at least five questions:

  1. 1What problem should it solve?
  2. 2What information does it receive?
  3. 3What rules should it apply?
  4. 4What result should it deliver?
  5. 5How will we verify that it works correctly?

For example, imagine we want to develop a small program to track achievement of a sales target. The specification could be:

Specification
OBJETIVO
Determinar si las ventas del mes alcanzaron la meta.

ENTRADAS
- ventas_mes
- meta_mes

REGLAS
- Si ventas_mes >= meta_mes → META CUMPLIDA
- Si ventas_mes < meta_mes → META NO CUMPLIDA

SALIDAS
- porcentaje de cumplimiento
- estado de la meta

CASOS DE PRUEBA
ventas = 120000, meta = 100000 → 120%, META CUMPLIDA
ventas = 80000, meta = 100000 → 80%, META NO CUMPLIDA

Before writing a single line of Python, the student already understands what should happen.

From specification to code

Once the specification is defined, we can progressively turn it into Python.

Python
ventas_mes = 120000
meta_mes = 100000

cumplimiento = ventas_mes / meta_mes * 100

if ventas_mes >= meta_mes:
    estado = "META CUMPLIDA"
else:
    estado = "META NO CUMPLIDA"

print(cumplimiento)
print(estado)

Several fundamental programming concepts arise naturally here:

  • —variables
  • —numbers
  • —mathematical operators
  • —comparisons
  • —conditionals
  • —information output

The difference is that every concept now has a reason to exist.

The student learns an if because they need to implement a rule they previously defined, not because it appears in chapter four of the course.

Teaching Python through needs, not syntax

This approach allows an introductory programming course to be completely reorganized.

Need Python concept
Store information Variables
Perform calculations Operators
Apply rules if, elif, else
Process many records for
Store multiple items Lists
Represent records Dictionaries
Reuse logic Functions
Read files Pandas
Handle errors Exceptions
Verify behavior Tests

Syntax stops being the starting point and becomes a tool for solving something.

An example: learning loops without starting by explaining loops

Suppose we have a list of sales transactions:

Python
operaciones = [
    12000,
    85000,
    42000,
    110000
]

The specification states:

Specification
OBJETIVO
Identificar operaciones superiores a S/ 50,000.

ENTRADA
Lista de operaciones.

REGLA
Si el monto es mayor a 50,000, mostrarlo.

SALIDA
Lista de operaciones que superan el umbral.

A natural question now arises: How do we apply the same rule to every transaction? At that point, the concept of iteration appears.

Python
for operacion in operaciones:
    if operacion > 50000:
        print(operacion)

The student has just learned a for, and did so to address a specific need.

SDD also changes the role of artificial intelligence

The emergence of tools such as ChatGPT, Claude, Gemini, and GitHub Copilot introduces a new challenge in teaching programming. Today a student can ask “Make me a Python program that analyzes sales” and receive hundreds of lines of code in seconds.

That is why evaluating only the ability to write code is starting to lose relevance. SDD changes the dynamic: the student takes on three responsibilities.

01

Specify

Correctly define the problem, inputs, rules, and outputs.

02

Generate or implement

Build the code directly or use an AI tool for a first version.

03

Verify

Check that the result actually meets the specification.

This changes the relationship between the student and AI. AI stops being merely a machine that “does the homework” and becomes an implementation assistant. Judgment remains with the student.

A simple classroom rule

One particularly useful practice is to establish a rule:

No code is generated until a verifiable specification exists.

Before opening the Python editor, the student must complete five blocks:

Specification template
1. OBJETIVO
¿Qué debe resolver?

2. ENTRADAS
¿Qué datos recibe?

3. REGLAS
¿Qué lógica debe aplicar?

4. SALIDAS
¿Qué debe entregar?

5. CRITERIOS DE ACEPTACIÓN
¿Cómo sabemos que funciona?

This structure forces students to think before programming and helps teachers quickly identify where the problem lies. If the program produces an incorrect result, we can ask:

  • —Was the specification incorrect?
  • —Was the rule incomplete?
  • —Did the code implement the rule incorrectly?
  • —Were test cases missing?

This leads to much more valuable conversations than simply correcting syntax errors.

A possible learning path

An introductory Python course based on SDD could be organized into eight sessions.

S1

From problem to specification

Identify objectives, inputs, rules, outputs, and acceptance criteria.

S2

From specification to Python

Variables, data types, operators, and results.

S3

Decision rules

Using if, elif and else to represent business rules.

S4

Processing multiple data items

Lists, dictionaries, and loops.

S5

Building functions

How to turn repetitive rules into reusable components.

S6

Real data

Reading and processing CSV or Excel files using Pandas.

S7

Validation

Test cases, errors, assert and validations.

S8

Complete project

Building a solution from the specification through final testing.

The result is a different progression: problem → logic → implementation → validation.

What changes for the student

With this approach, learning Python stops meaning memorizing commands. Students begin to develop other abilities:

  • —break down problems
  • —turn needs into rules
  • —identify inputs and outputs
  • —define verifiable criteria
  • —read code
  • —detect errors
  • —test solutions
  • —work with AI assistants

These skills are especially important in a context where more and more code can be generated automatically.

Programming is no longer just about writing code

For many years, learning programming meant learning to produce instructions for a computer. Artificial intelligence is partially changing that definition: it will become increasingly common for a person to describe an expected behavior and for a tool to generate part of the implementation.

In that scenario, knowing how to specify a problem correctly becomes a core competency. That is why teaching Python through Spec-Driven Development can be a particularly useful way to introduce programming to new students.

Instead of starting the class with “today we will learn variables,” we can start with something much closer to reality:

“We have a problem. Let's define exactly what the program should do.”

And from there, let Python appear as what it really is: a tool for turning a well-defined idea into an executable solution.