Skip to content

c. Practical Examples

Responsible Programming and Code Quality

These examples use a light I do - We do - You do model. The goal is not just to read the answer, but to practise noticing problems, naming them correctly, and improving code or decisions step by step.


Example 1 - I do: Checking an AI-generated code snippet

string n = "";
int score = Convert.ToInt32(Console.ReadLine());
if (score > 0 || score <= 100)
{
    Console.WriteLine("Accepted");
}

Try first

Before opening the teacher walkthrough, write down:

  1. one logic problem
  2. one readability or maintainability problem
  3. one change you would make first
Teacher walkthrough

When I inspect this code, I would point out:

  1. The logic is incorrect. The condition uses ||, so almost every number will be accepted. A valid score check should normally use &&.
  2. The variable name is weak. n tells the reader almost nothing.
  3. There is no prompt to the user. The program expects input without explaining what is required.
  4. The code is difficult to maintain. Another programmer would need to infer the purpose of the snippet from context.
One possible improved version
Console.WriteLine("Enter a score from 0 to 100:");
int studentScore = Convert.ToInt32(Console.ReadLine());

if (studentScore >= 0 && studentScore <= 100)
{
    Console.WriteLine("Accepted");
}
else
{
    Console.WriteLine("Invalid score");
}

Focus: AI-generated code still needs human checking for logic, readability and maintainability.

Exam link: Students should be able to evaluate AI-generated or copied code rather than assuming it is correct.


Example 2 - We do: Improving readability and maintainability

Starting version

double p = 12.5;
int q = 4;
double t = p * q;
Console.WriteLine(t);

Try first

Before opening the model answer:

  1. rename each variable so its purpose is clear
  2. improve the output line
  3. add spacing so the code is easier to read
One possible improved version
double ticketPrice = 12.50;
int ticketQuantity = 4;
double totalCost = ticketPrice * ticketQuantity;

Console.WriteLine("Total cost: $" + totalCost);
What changed?
  • variable names now describe purpose
  • the output message is clearer
  • spacing makes the code easier to scan
  • the program is easier to revisit later

We do prompt

Compare your version with the model answer. If yours is different but still clear and meaningful, that is fine. The goal is clarity, not one exact wording.

Focus: Readability supports maintainability.

Exam link: Naming, formatting and clarity are common "explain why" points in short-answer questions.


Example 3 - We do: Deciding whether low-code is suitable

Scenario

A teacher wants a simple form that lets students submit their name, class and topic preference for a coding workshop. The form needs to be built quickly and the data only needs to be stored in a simple list.

Try first

Decide:

  1. Would you choose low-code here: yes, no, or maybe?
  2. What is your strongest reason?
  3. What maintenance risk would still need attention?
One possible model response

A low-code tool could be suitable here because:

  • the interface is simple
  • development speed matters
  • the logic is straightforward
  • the first version does not need complex custom processing

Even in a low-code tool, the developer still needs to consider:

  • whether the data is stored safely
  • whether the form is clear for users
  • whether the solution can be maintained later

Focus: Low-code speeds up development, but it does not remove the need for good design decisions.

Exam link: Students should justify why a tool is or is not suitable for a particular situation.


Scenario

A student wants to use:

  • a background image copied from a Google search
  • a code sample from a public tutorial site
  • an open-source library with clear licence terms

Your task

For each item, decide:

  1. Can it be used immediately?
  2. Does the licence or copyright need to be checked?
  3. What action should the student take before including it in a folio solution?

Retrieval Prompt

Before looking anything up, try to explain from memory what copyright and intellectual property mean in software development.

Focus: Responsible reuse means checking ownership and licence conditions before adding third-party material.

Exam link: Legal requirements are often assessed through scenarios rather than direct definition questions.


Example 5 - You do: Quick retrieval grid

Complete the table from memory, then check your answers against the What You Need To Know page.

Term What does it mean? Why does it matter?
Low-code
AI code generator
Readability
Maintainability
Copyright
Debugger

Study Tip

Retrieval practice is strongest when you try to answer first without notes, then correct your thinking afterwards.