C3.2 Read and alter existing code, including code that involves sequential, concurrent, repeating, and nested events, and describe how changes to the code affect the outcomes.
Skill: Reading a Code
Code reading involves interpreting blocks or commands to deduce the meaning of the code. This allows the student to make predictions related to the behaviour of the code. Code reading is also an important part of debugging, the identification and correction of errors in the code. By reading the code, it is possible for the student to identify the reason(s) why it is not working. Note that this skill does not correspond to the computer reading the code, but rather to the student reading the code to verify it.
Students can do code reading to identify the pattern of a sequence, as in the following code:
![](/img/activite/algebre/en/4e/VE4_Algebre_Image135_en.png)
Students may notice that the pattern looks like this:
(Move token), (Pause for one second), (Stamp)
Skill: Modifying Code
The culture of computer programming is one of sharing. Many programs are created based on existing code. Modifying code allows the student to start from an existing and functional code sequence in order to build something new. Modifying code can also be done to simplify it or to demonstrate that there is more than one way to represent the same situation using code. If necessary, the student can also modify erroneous code to make it functional, a process called debugging.
Using the same code as in the previous example, the student could identify blocks that simplify the code by isolating the pattern. The resulting code might look like this:
![](/img/activite/algebre/en/4e/VE4_Algebre_Image136_en.png)
In this case, the student would have chosen to use a loop to isolate the pattern and simplify the code.
Skill: Describing the Impact of Changes on Code
Trial and error learning is an important part of creating code sequences. However, it is important that the student be able to justify their choices of modifications to an existing code by making predictions about the effect of the changes on the behaviour of the code.
During pattern creation using geometric properties, the student has several variables to play with without making the code non-functional. In the following code:
![](/img/activite/algebre/en/4e/VE4_Algebre_Image126_en.png)
The following pattern is created:
![](/img/activite/algebre/en/4e/VE4_Algebre_Image127_en.png)
The following questions could be asked of the student:
- What changes will be needed to create triangles instead of rectangles?
- What happens if the number of degrees of rotation increases towards the end of the code?
- Is the "raise the pen" block necessary? What is its role?
- How will more repetitions of the outer loop change the appearance of the pattern?