How to Start a Programming Assignment: Solve It by Hand

Short answer: Before you write any code, pick a small input from the assignment and work out the correct output by hand, writing down every step. In one classroom study, students who had to do this before coding finished the task more often and needed fewer attempts.

What the study found

Most advice for a stuck student says "break it into smaller pieces." That helps only if you already understand what the program is supposed to do. Often you do not, and you do not know it yet.

Prather et al. (2019) tested a simple fix in an intro programming course taught in C++. Two course sections got the same programming problem. One section could start coding right after reading the prompt. The other section first had to answer a quiz: given a random input, what output should the program produce? Those students could not begin coding until they got it right.

The results favored the quiz group. About 76% of them finished the task correctly, compared with about 53% of the group that started coding immediately. Among students who finished, the quiz group averaged about 4.5 code submissions, against about 7.6 for the other group. Finishing took about the same time in both groups.

The researchers also sat with students while they worked and had them think aloud. Students who got through the quiz often understood why it was there. Some still misread the problem. Two students believed they were solving a different task, and the quiz did not catch that.

Why it works

A prompt can feel clear until you try to apply it. Reading "return the average of the positive numbers" seems easy, but you have not yet decided what happens with zeros, an empty list, or how many decimals to show. Working one example by hand forces those choices into the open, before they turn into bugs.

It also gives you something to check against. When your code later prints a wrong answer, you know the right one, so you can find the step where the two paths split.

A broader line of work points the same way. Loksa et al. (2016) taught high school students to name which stage of problem solving they were in, such as interpreting the problem or designing a solution. In their two-camp experiment with 48 students, the guided group showed more self-awareness about their strategies and higher confidence. Both groups were about equally likely to finish the assigned task, so the benefit there was in how students worked, not in a higher finish rate.

How to do it

  1. Reread the prompt and underline what goes in and what comes out. Write one line each: "Input: a list of exam scores. Output: the average of scores above 50." If you cannot write these lines, you have found your real problem. Ask your instructor or reread the examples.
  2. Choose one small, concrete example. Use the sample from the assignment if there is one. If not, invent a tiny input you can handle in your head, like three numbers. Avoid anything with a hundred rows.
  3. Solve it on paper, one step at a time. Do not skip to the answer. Write what you actually do: "Look at 72, it is above 50, add it to the total." Each line you write is a line your program will need.
  4. Try a second example that could break your approach. Use an empty input, a single item, a repeat, or a zero. Notice if your by-hand method needed a special rule.
  5. Turn your steps into comments, then code under each one. Your hand-solution is now an outline. Run your code on the same example and compare it with your written answer.

Try it tonight: Open an assignment you have not started. Spend ten minutes writing one input and its correct output, with every step in between, before you type any code.

Common mistakes

Picking an example that is too easy. If the example hides the tricky part of the problem, your hand-solution will too. Add a second case.

Solving it in your head. Thinking "I know how this goes" is how you skip the steps. The value is in the written steps.

Checking the answer against your own code. Work the example out first, then run the program. If you run the code first, you will tend to trust whatever it prints.

If the page is still blank after this, the blank page method gives another way to get words down. For exams that ask you to trace code, how to study for a CS exam covers the same hand-tracing skill.

Where the research stops

This was a small study at one school, and the groups were existing course sections, not randomly assigned. The authors themselves described the results as promising but not conclusive. The quiz was also built into the course software, and you will be doing the step yourself, with no one checking your answer. A friend, a classmate, or the sample output in the assignment can fill that role. Treat the study as a good reason to try the habit, not a guarantee.

Sources

  1. Prather, J., Pettit, R., Becker, B. A., Denny, P., Loksa, D., Peters, A. L., Albrecht, Z., & Masci, K. (2019). First things first: Providing metacognitive scaffolding for interpreting problem prompts. In Proceedings of the 50th ACM Technical Symposium on Computer Science Education (SIGCSE '19) (pp. 531-537). ACM. https://doi.org/10.1145/3287324.3287374
  2. Loksa, D., Ko, A. J., Jernigan, W., Oleson, A., Mendez, C. J., & Burnett, M. M. (2016). Programming, problem solving, and self-awareness: Effects of explicit guidance. In Proceedings of the 2016 CHI Conference on Human Factors in Computing Systems. ACM. https://doi.org/10.1145/2858036.2858252