Program Maintainability
What is program maintainability?
- Maintainability is used to ensure programmers can easily understand what a program is doing months or years after having first written it
- Maintainability is also used when programming as part of a large team, so each programmer working on the team understands what each section is doing
How are programs maintained?
- Commenting of code: to explain the purpose of the code in a particular section
- White space: to make each section clear and easy to see
- Indentation: to show each instance of selection and iteration and to make it clear which code belongs to which clause in the program
- Sensible variable names: so that the name explains what that variable or data structure does and to prevent confusion later in the development process
- Use of sub-programs: functions or procedures split up programs into reusable sections of code which can remove the need for duplicating code and also increase the overall structure of the code
An example of maintainability
- The first image below shows the code for a bubble sort algorithm written in Python
- The code does not include any of the maintainability features mentioned in this section
- The second image, below, is the same program however, it clearly shows the use of
- comments
- meaningful variable names
- white space
- indentation
- By including each of these, the code immediately becomes easier to
- read
- understand
- debug
- improve
Worked example
The area of a circle is calculated using the formula , where is equal to 3.142 and is the radius.
George has written a program to allow a user to enter the radius of a circle as a whole number, between 1 and 30, and output the area of the circle.
radius = int(0)
area = float(0.0)
radius = int(input("Enter radius: "))
if radius < 1 or radius > 30:
print("That radius is invalid")
else
area = 3.142 x(radius2)
print(area)
Explain, using examples from the program, two ways Finn can improve the maintainability of the program. [6]
How to answer this question
- To score full marks on this type of question you will be awarded
- 1 mark for identifying a maintainability feature
- 1 mark for explaining how it aids maintainability
- 1 mark for applying it to the context in the question
Answers: Maximum of 3 marks per method
- Comments/annotation
- To explain the key functions/sections
- E.g. any relevant example, such as line 4 checks the input is valid
- Indentation
- To show where constructs/sections start and finish
- E.g. indenting within IF statement
- White space
- So the code appears easier to read and understand
- E.g. leaving a line break after the radius input