← VCE Software Development U4O1

Maintainability improvements in code

Code organised so it can be fixed or extended later without breaking other parts, using small functions, classes that hide detail and constants instead of repeated values.

Understanding Maintainability improvements in code in VCE Software Development U4O1

What it does: The double underscore makes balance private. Other code must use methods like deposit(), so the inside of the class can change safely. Using GST_RATE instead of typing 0.1 everywhere means one edit updates every calculation. A named constant such as PASS_MARK explains what the number means and can be changed in one place. With one small function you fix the bug once. Copied code means fixing it six times and risking missing one. Changing one constant is quick and safe. Hunting for every 4 is slow, and you might change a 4 that means something else. Repeating the same value makes code hard to maintain, because one missed edit creates a bug. A constant fixes this.

Common mistakes: A function header must end with a colon. It should be def add_tax(price): so the small function can hold the tax calculation in one place. A single = stores the constant's value. == compares values, so MAX_USERS would never be created. It should be MAX_USERS = 30.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 82–114) and word search (Modules 3–114).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which function is easier to maintain?
Small functions that each do one job, such as calculate_total() and print_receipt()One huge function that reads input, calculates, prints and saves everything
Matches
total = cost * 0.1 + fee * 0.1 + tip * 0.1
↓
The value 0.1 is repeated (a magic number). If the rate changes, every copy must be found and edited. Store it once as a constant such as RATE.
Applying
Meanings
Term
maintainable code
Meaning
Code organised so it can be fixed or extended later without breaking other parts, using small functions, classes that hide detail and constants instead of repeated values.
Practice
GST_RATE = 0.1
Testing
Gaps
total(price, qty):
Check Answer
Spots
1TAX = 0.1
2def add_tax(price)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Leopard' badge — Savannah Perfectionist, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which function is easier to maintain?
A. One huge function that reads input, calculates, prints and saves everything
B. Small functions that each do one job, such as calculate_total() and print_receipt() ✓
Small functions each do one job. You can fix or change one without breaking the others, which makes the code maintainable.
2. A shop's GST rate of 0.1 is used in 12 places in a program. What is the more maintainable approach?
A. Create a constant GST_RATE = 0.1 and use it everywhere ✓
B. Type 0.1 in each place it is needed
With a constant you change the value once and every use is updated. Repeating 0.1 means you could miss one when the rate changes.
3. True or false: A class that hides its detail (for example, keeping balance private) helps make code maintainable.
A. True ✓
B. False
Hiding detail means other parts of the program use only the class's methods. You can change how the class works inside without breaking the rest of the program.
4. Which line uses a constant to make code easier to maintain?
A. if score >= 50:
B. if score >= PASS_MARK: ✓
A named constant such as PASS_MARK explains what the number means and can be changed in one place.
5. A bug is found in how a discount is calculated. In which program is it easier to fix?
A. One where the discount is worked out in a single small function, apply_discount() ✓
B. One where the discount code is copied and pasted into six different places
With one small function you fix the bug once. Copied code means fixing it six times and risking missing one.

Match the Pairs

TAX_RATE = 0.1 → A constant that stores a value once, so it can be changed in one place instead of many
def calculate_total(items): → A small function that does one job, so it can be fixed or reused without affecting other code
A class can hide its detail by keeping data private, so other code uses methods instead of changing it directly → self.__balance = 0
Replace a repeated number with a named constant so a future change is made in one place → price = base * (1 + GST_RATE)
total = cost * 0.1 + fee * 0.1 + tip * 0.1 → The value 0.1 is repeated (a magic number). If the rate changes, every copy must be found and edited. Store it once as a constant such as RATE.
def do_everything(): read_input() calc_marks() print_report() → One big function does many jobs, so a change to one job can break the others. Split it into small functions that each do one job.

Key Term

maintainable code
Code organised so it can be fixed or extended later without breaking other parts, using small functions, classes that hide detail and constants instead of repeated values.

Fill in the Blanks

1. def total(price, qty): return price * qty
Hint: Type the keyword that starts a small, reusable function.
2. RATE = 0.1 total = price * (1 + RATE)
Hint: Type the constant name so the value is not repeated in the calculation.
3. class Account: def getBalance(self): return self.balance
Hint: Type the keyword that groups data and methods together into one unit.
4. class Account: def getBalance(self): return self.balance
Hint: Type the first parameter a method uses to refer to its own object.
5. PASS = 50 def isPass(mark): return mark >= PASS
Hint: Type the keyword that sends the result back from this small function.

Spot the Error

Question 1
A TAX = 0.1
B def add_tax(price)
C return price * (1 + TAX)
D print(add_tax(50))
Line B — A function header must end with a colon. It should be def add_tax(price): so the small function can hold the tax calculation in one place.
Question 2
A # Settings in one place
B MAX_USERS == 30
C def can_join(count):
D return count < MAX_USERS
Line B — A single = stores the constant's value. == compares values, so MAX_USERS would never be created. It should be MAX_USERS = 30.
Question 3
A class Account:
B def __init__(self):
C self._balance = 0
D def deposit(amt):
E self._balance += amt
Line D — Every method in a class needs self as its first parameter so it can reach the hidden data. It should be def deposit(self, amt):.
Question 4
A function area(w, h):
B return w * h
C def show_area(w, h):
D print(area(w, h))
Line A — Python defines a function with the keyword def, not function. It should be def area(w, h): so the small function can be reused.
Question 5
A 0.1 = GST
B price = 40
C total = price * (1 + GST)
D print(total)
Line A — The name goes on the left and the value on the right. It should be GST = 0.1 so the constant can be reused instead of repeating 0.1.

Student with a class code? Join your class →