The same snippet can be used to understand the basics or to prepare for a review. Provide a function, an example input, and the specific question. Indicate any concepts you already know, such as loops, data types, or transactions.
Choose your approach
- To begin, ask students to track three values at each step and explain the result using the function's vocabulary.
- To delve deeper, ask about invariants, boundary cases, side effects, and costs depending on the data size.
- Compare the explanation to the execution using a typical example and a challenging example.
Explain this function with a three-element input. First, create a simple trace, then identify the ordering assumption that could be violated and propose a test.
Check your understanding
Predict the result of a fourth input before running the code. If the explanation cites a library, open its documentation for the version used. Keep a short comment about the constraint, which could easily be overlooked.
Have students explain a sorting function
Give them a function that sorts tasks by due date and a set of four inputs. Include two identical dates and one task without a date. First, ask for a simple trace, showing the order before and after sorting. Then, ask what happens in case of a tie and how tasks without dates are handled.
For a first reading, have students explain only one concept at a time, such as the sort key. For a more advanced review, ask if the function modifies the original list, if the order between two identical entries is preserved, and what the cost is with each additional element. Compare the answers to the code and documentation of the version being used.
Perform a comprehension test
- Add a fifth task and predict where it should appear.
- Run the example, then note the first difference between your prediction and the actual result.
- Modify one rule at a time. For example, change the position of tasks without a date and run the test again.
Keep a sample output and a short note about the rule that might surprise another developer. This record helps verify comprehension and serves as a starting point for testing a change.
See also
Adapt the explanation to the reader's question
To understand a function, start by clarifying your objective. You might want to know what the function receives, why a value changes, or how to add a case. Give NEO the relevant passage and an example input. Ask for an initial reading that follows the values in the order of the operations. For a sorting function, keep an example with two elements having the same priority to verify how they are ranked.
With a beginner reader, ask for a description of the steps and a definition of the terms used. With an experienced reader, ask for the expected conditions, the calls that use the result, and the boundary cases. The same passage can thus provide a short explanation of the behavior and a second reading on the implementation choices. The initial example should produce the same result in both versions.
Explain this function with the provided example. Show the values that change at each step. State the assumptions, then give me another input whose result I can predict.
Verify the explanation by running this example in the project or in a standalone snippet. Compare the observed result to the predicted result. If the explanation assumes that the function returns a new list, check what happens to the original list. Note the verified behavior near the passage. The next reading will then be able to distinguish a confirmed description from an assumption about a still unknown part of the code.