liveBook · Manning

Think-code-test-debug-repeat cycle

As explained in Get Programming: Learn to code with Python

An iterative programming workflow of understanding a problem, implementing a solution, testing it, debugging defects, and repeating until the solution works.

The think-code-test-debug-repeat cycle is an organized way to solve programming problems. First understand what the task asks, then choose an algorithm—a recipe of steps—before writing code. Run the program with different inputs, compare actual results with expected results, fix incorrect behavior, and repeat until the code passes its tests. section 2.3 section 2.5

Figure 2.3. This is the ideal way to approach solving a problem with programming. Understand the problem before you write any code. Then test the code that you write and debug it as necessary. This process repeats until your code passes all tests.

Use the cycle diagram as a quick roadmap: understand the problem before coding, then test and debug repeatedly until the solution works according to its specification. section 2.3

Work through the cycle in this order:

  • Think: identify the task, determine its inputs and outputs, and decide what series of steps could solve it. Do not begin by writing code immediately. section 2.3 section 2.5
  • Code: implement the chosen algorithm, experimenting with the necessary operations and repeated parts. section 2.3
  • Test: run the program with different inputs and check whether its actual output matches the expected output. section 2.3
  • Debug: locate the lines causing incorrect behavior and change the implementation. Repeat the cycle as many times as necessary. section 2.3

A recipe for a program

Baking provides a useful analogy. Think about what baked good the task requests and choose or create a recipe. Code by combining the ingredients and following the steps. Test the result by checking whether it matches the requested product. Debug by changing a problem ingredient—for example, reducing salt if the result is too salty—and repeat. section 2.3

Readable code supports the cycle: use descriptive names and comments that explain the problem and the solution. More than one implementation may produce the same correct behavior, so matching the required inputs and outputs matters most. section 2.5 section 13.3

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains four procedural steps with a baking analogy and input-output checks, while deferring detailed debugging techniques.
Examples
Uses baking recipes, expected-versus-actual outputs, and Python conditional programs as concrete illustrations.
What it assumes
Assumes a programming problem to solve and teaches the planning-before-coding workflow, including algorithms, tests, and debugging.
What you can do after
Apply it to plan, implement, test, debug, and refine programs against their required inputs and outputs.
How it connects
Connects algorithms, problem specifications, inputs and outputs, testing, debugging, and readable code.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.