Refactoring code to improve it
Rewriting working code to make it clearer or simpler (e.g. renaming variables, moving repeated lines into a function) without changing what it does, then re-running tests.
Understanding Refactoring code to improve it in VCE Software Development U4O1
What it does: A test case checks the output after the change. If it still passes, the behaviour has not changed. Both lines calculate the same value. Only the variable names changed, so this is refactoring and not a new feature. Refactoring changes how the code is written, not what the program does. New features are a different job. Even small changes can introduce mistakes, so you re-test to prove the behaviour is unchanged. Renaming a variable makes the code easier to read but leaves the output the same. Calculating GST changes behaviour. A function removes repetition, so a fix or change only needs to be made in one place.
Common mistakes: Refactoring must not change what the code does. Changing * to + gives 7 instead of 12, so the tests would fail. It should be price * qty. The variable was renamed to area, but this line still uses the old name areas, which causes a NameError. It should be print(area).
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
refactoringFill in the Blanks
Spot the Error
Student with a class code? Join your class →