The purpose of maintainability The process of ensuring that a program is easy to understand, modify and update. is to ensure that, over time, a programSequences of instructions for a computer. can be easily maintained.
A programmer may decide to return to a program they wrote some time before in order to add an extra feature. Additionally, another programmer may wish to modify the program in order to improve it or debugThe process of finding and correcting programming errors. an error.
In both situations, the understanding of the program, how it works and the purpose of the code will be made easier if the program is written in a maintainable style. This includes using:
comments
naming conventions
indentation
Comments
Comments are lines in programs that provide information about what the different parts of the program do. They serve no other purpose, and are not executed when the program is run - the program simply ignores them and moves on to the next line of code.
Different languages implement comments in different ways. In Python, for example, a comment begins with a hash symbol, and is coloured red:
#ensures the input is restricted to a y or an n
Naming conventions
Many programmers choose meaningless variableA memory location within a computer program where values are stored. names such as x or y. While a program will run with such names, it makes understanding the purpose of the variable much more difficult. Programmers should choose a variable name that reflects the purpose of the variable and the dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. it is intended to hold:
H - poor choice. What does it mean?
height - better choice. The value to be inputted will be a number.
Indentation
Code within selections or iterationThe repetition of a block of statements within a computer program. should be indented. This allows the programmer to easily see which code falls within the selection or iteration, and where it ends.
Some programming languages, such as Python, indent such code automatically.
do
for count = 1 to 10
print("Hey!")
next count
again = input("Enter y to go again")
again.lower
until again !="y"