Program Maintainability (OCR GCSE Computer Science): Revision Notes
📚 Revision Notes
Programme Maintainability
Maintainability refers to designing a programme in a way that makes it easy to read, understand, and modify. Well-maintained code ensures that future developers (or even the original programmer) can efficiently make updates or fix issues without introducing new errors. Following good practices helps reduce the time and effort needed to maintain a programme.
Key Practices for Maintainability
Use of Sub Programs
- Sub programmes, such as functions and procedures, help organise code into smaller, reusable sections.
- This reduces repetition, makes the code easier to follow, and allows changes to be made in one place instead of multiple locations.
Naming Conventions
- Using meaningful and descriptive variable names helps others understand what each part of the programme does.
- For example, using totalScore is better than x as it clearly states the purpose of the variable.
- Consistent naming makes the code easier to read and maintain.
Indentation
- Indentation visually groups code blocks, making it easier to follow the flow of the programme.
- It helps identify which statements belong to which control structures (like loops and conditionals).
- Consistent indentation helps with finding sections of code and fixing errors more efficiently.
Example:
if userInput == "yes":
print("You chose yes.")
else:
print("You chose no.")
Proper indentation makes it clear which statements belong to the if and else blocks.
Commenting
- Comments are explanations written in code to describe what specific parts of the programme do.
- They don't affect how the programme runs but help developers understand the code quickly, especially when revisiting the programme after a long time.
- Useful comments explain why something is done rather than simply describing what the code does.
Example of Comments:
# Calculate the user's age based on the birth year provided
age = currentYear - birthYear
Comments help other developers (or future you) grasp the code's purpose more quickly.
Why Commenting is Important
- It helps with code readability, making it easier for others (or yourself) to maintain or update the programme in the future.
- Explains complex logic that may not be obvious at first glance, ensuring smooth transitions when teams work together on a project.
- Prevents mistakes during updates or fixes by clearly outlining what each section of code is responsible for.
Good Programming Practices Overview
| Practice | Description |
|---|---|
| Indentation | Organises code visually, making it easier to follow. |
| Comments | Provides explanations of code to help understand its purpose and function. |
| Sensible Variable and Subroutine Names | Meaningful names improve clarity and help others follow the code more easily. |
infoNote
Key Points to Remember
- Well-structured code with sub programmes reduces redundancy and makes updates easier.
- Consistent naming conventions and indentation make the code readable and easy to follow.
- Comments provide clarity, explaining the logic and purpose of the code, and making future maintenance simpler.