• Foundation
  • About 12 min
  • 5 practice questions

From problem to program: the programming cycle, comments, testing and good names

List the stages of writing a program, explain the roles of comments and an editor, and design simple test cases including boundary values.

If something looks wrong, please tell us.

Experienced programmers do not begin by typing code. They follow a cycle of stages that turns a problem into a working, checked program. Knowing the stages helps you answer exam questions and, more usefully, write programs that work the first time more often.

The stages

  • 1. Understand the problem: what is given and what is wanted?
  • 2. Plan the solution: write an algorithm or draw a flowchart.
  • 3. Write the code: translate the plan into a programming language, in an editor.
  • 4. Translate and run: a compiler or interpreter turns the code into something the computer can run. Syntax errors are reported here.
  • 5. Test: run the program with chosen inputs and compare the results with expected answers. Logic errors appear here.
  • 6. Debug: find and fix the faults, then test again.
  • 7. Document and maintain: write comments and instructions, and update the program when needs change.

An IDE (integrated development environment) is a single program that combines an editor, a translator and debugging tools, so a programmer can do stages 3 to 6 in one place.

Comments and names

A comment is text in the code that the computer ignores but people read. It explains what the code does and why. Good comments explain the purpose; they do not repeat every line. Choose clear names for variables, such as totalMarks rather than t. In most languages a name must start with a letter or underscore, cannot contain spaces and cannot be a reserved word of the language.

Testing with test data

A test case is a chosen input with the output you expect. Good test data includes normal values, boundary values (the edges, where mistakes often occur) and invalid values (which the program should refuse or handle). Suppose a program prints Pass if marks are 40 or more and Fail otherwise.

Test plan for the pass rule
Test typeInputExpected output
Normal65Pass
Normal12Fail
Boundary40Pass
Boundary39Fail
Invalid-5An error message

Worked example 1: order the stages

Put these in order: run the program, plan an algorithm, understand the problem, fix the faults, write the code. The correct order is understand the problem, plan an algorithm, write the code, run the program, fix the faults. After fixing, you test again.

Worked example 2: why test the boundary

A programmer writes IF marks > 40 THEN Pass, when the rule says 40 or more should pass. Test data of 65 and 12 both give the right answers, so the fault is not noticed. The boundary test with 40 shows the fault: the program prints Fail but the expected answer is Pass. The fix is to write marks >= 40. This is why boundary values are always tested.

Worked example 3: good and poor names

A student writes x = y z to compute the area of a rectangle. A better version is area = length breadth, which explains itself without comments. Names such as total, count, area and price are easy to read; names such as a1 and tmp2 tell the reader nothing.

Understand, plan, code, run, test, debug, document. Test normal, boundary and invalid data.

Key takeaways

  • Plan before coding; test after coding.
  • Boundary values are where faults hide.
  • Comments and meaningful names make a program easier to maintain.

Check your understanding

  1. 1. Which stage comes immediately after writing the code?

    1. Planning the algorithm
    2. Understanding the problem
    3. Documenting it
    4. Translating and running it
    Show answer

    Answer: D. After the code is written it is translated (compiled or interpreted) and run.

  2. 2. A test input at the very edge of the allowed range is called

    1. Normal data
    2. Boundary data
    3. Random data
    4. Invalid data
    Show answer

    Answer: B. Boundary data lies at the edges of the valid range, where faults are most likely.

  3. 3. What is a comment in a program?

    1. Text for readers that is ignored
    2. A line that the computer prints
    3. An error message from the editor
    4. The file name of the program
    Show answer

    Answer: A. Comments are ignored when the program runs and exist to help people understand the code.

  4. 4. An IDE is

    1. A type of laser printer
    2. A kind of computer virus
    3. A suite of programming tools
    4. An error code for syntax
    Show answer

    Answer: C. An integrated development environment combines the tools a programmer needs.

  5. 5. The rule is 'Pass if marks are 40 or more'. Which input best tests the boundary?

    1. 40
    2. 100
    3. 0
    4. 65
    Show answer

    Answer: A. 40 is the edge value: it must give Pass, and a wrong comparison such as > 40 would fail on it.

Privacy · Terms · Refunds · Delivery