C3.2 Read and alter existing code involving the analysis of data in order to inform and communicate decisions, and describe how changes to the code affect the outcomes and the efficiency of the code.

Skill: Reading Code


Reading code involves interpreting blocks or commands to deduce their meaning. This allows the student to make predictions about the outcome of the code. Reading code is also an important part of debugging, which is the identification and correction of errors in the code, because by reading the code it is possible for the student to determine the reason(s) why it is not working. Note that we are not talking about the computer reading the code, but rather the student reading the code and checking it.

Skill: Altering Code


The culture of computer programming is one of sharing, and many pieces of software are created based on existing code. Altering code first allows the student to start from an existing and functional code to build something new. The alteration of a code can also have as a goal to simplify it, or to demonstrate that there is more than one way to represent the same situation with code. We could also talk here about efficiency, which in the context of coding means using a minimum number of blocks or commands to achieve the desired outcome. If necessary, the student can also alter erroneous code in order to make it functional, a process called debugging.

For example, sometimes there are different coding tools that will do a job more efficiently than others. Altering code to make it useful in different software or in a different language can, in the long run, be more efficient.

The calculation of the mean for a set of data in block-based coding software might look like this:

Block of codes.Control block stating, ‘’repeat until answer equals n’’.Inside 4 nested blocks. Sensing block stating ‘’ask what is the data value, question mark, and wait’’.List block stating, ‘’add’’ sensing block, ‘answer’’ of list of data’’. Variables block stating, ‘’change sum by’’ sensing block stating, ‘’answer’’.Variables block stating, ‘’set average to sum divided length of list of data’’.

While the same outcome can be obtained with a single line of code in a spreadsheet.

Electronic spreadsheet showing how to calculate the average.

Skill: Describing the Impact of Changes on Code


As much as trial and error is an important part of creating code, it is important that the student be able to justify their choices of alterations to an existing code by making predictions about their effect on the outcome of the code. This is also important when altering code to make it efficient, as it is possible to introduce changes that have an unintended or negative impact on the final outcome.

For example, the collection interval in a code that collects ambient temperature data in a room can affect the data. It would be possible to first ask students what would happen if the temperature was measured and recorded every second, or every minute, or every hour, and how these alterations might change the visualization of the data.