Maintaining Programs (Cambridge (CIE) O Level Computer Science)
Revision Note
Written by: Robert Hampton
Reviewed by: James Woodhouse
Maintaining Programs
How do you write programs that are easy to maintain?
Easy to maintain programs are written using techniques that make code easy to read
Programmers should be consistent with the use of techniques such as:
Layout - spacing between sections
Indentation - clearly defined sections of code
Comments - explaining key parts of the code
Meaningful variable names - describe what is being stored
White space - adding suitable spaces to make it easy to read
Sub-programs - Functions or procedures used where possible
When consistency is applied, programs are easy to maintain
Example easy to-maintain program
Python code |
---|
# ----------------------------------------------------------------------- """ Calculates the area of a triangle given its base and height. Inputs: base (float): The length of the triangle's base (positive value). height (float): The height of the triangle from the base (positive value). Returns: The calculated area of the triangle (float). Raises: ValueError: If either base or height is non-positive. """ # -----------------------------------------------------------------------
# ----------------------------------------------------------------------- # Prompts the user for triangle base and height, calculates and prints the area # -----------------------------------------------------------------------
# Call the area calculation function
# ------------------------------------------------------------------------ # Main program # ------------------------------------------------------------------------
|
Last updated:
You've read 0 of your 5 free revision notes this week
Sign up now. It’s free!
Did this page help you?