Maintaining Programs (Cambridge (CIE) IGCSE Computer Science)

Revision Note

Robert Hampton

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

def calculate_area_of_triangle(base, height):
    if base <= 0 or height <= 0:
        raise ValueError("Base and height must be positive values.")

    area = 0.5 * base * height  # Corrected multiplication syntax
    return area

def main():
    # -----------------------------------------------------------------------
    # Prompts the user for triangle base and height, calculates and prints the area
    # -----------------------------------------------------------------------
    try:
        base = float(input("Enter the base of the triangle: "))
        height = float(input("Enter the height of the triangle: "))

        # Call the area calculation function
        area = calculate_area_of_triangle(base, height)

        print(f"The area of the triangle is approximately {area:.2f} square units.")

    except ValueError as error:
        print(f"Error: {error}")

# ------------------------------------------------------------------------
# Main program
# ------------------------------------------------------------------------

main()

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.