2.3.3

Maintainability

Test yourself

Maintainability

Maintainable code is code that can be read, understood, and fixed by other developers. There are a few best-practice techniques to help write maintainable code, including:

Illustrative background for CommentsIllustrative background for Comments ?? "content

Comments

  • Comments should be used throughout the code to:
    • Explain complex processes.
    • Clarify the purpose of algorithms.
    • Clarify the purpose of a subroutine, as well as its parameters and return type and value.
Illustrative background for IndentationIllustrative background for Indentation ?? "content

Indentation

  • It is good practice to keep indentation of code consistent throughout the code.
  • When a new block of code opens, it should be indented to the right.
  • When a block of code closes, it should return to the left.
  • This makes code easier to read by visualising the scopes involved.
Illustrative background for Identifier namesIllustrative background for Identifier names ?? "content

Identifier names

  • Identifier names should be clear about their purpose. For example, which of the following two examples makes more sense:
    • newBalance = oldBalance * INTEREST_RATE;
    • a = b * c;
Illustrative background for Code structureIllustrative background for Code structure ?? "content

Code structure

  • Code should be well structured through the use of subroutines.
  • This allows people to identify a single subroutine that they need to reuse or work on.
Illustrative background for Parameters vs global variablesIllustrative background for Parameters vs global variables ?? "content

Parameters vs global variables

  • It is good practice to pass data around the program using parameter passing rather than using global variables.
  • This is because passing parameters prevents other subroutines from unexpectedly changing the value of the variables.

Comments

Comments are lines of code that are ignored completely by the computer.

Illustrative background for What are comments?Illustrative background for What are comments? ?? "content

What are comments?

  • A comment is a line of code that is completely ignored by the computer.
Illustrative background for Purpose of commentsIllustrative background for Purpose of comments ?? "content

Purpose of comments

  • Comments can be used to add description to your code to make it easier for other people to understand.
  • They can also be used to leave notes and reminders to yourself as you work on a complex program.
Illustrative background for How to commentIllustrative background for How to comment ?? "content

How to comment

  • To write a comment in most languages, you must use a special character which tells the computer to ignore the rest of the line:
    • In Python, that character is a #.
    • In C-style languages it is //.
  • The exact character depends on the language being used.

Jump to other topics

1Computer Systems

1.1Systems Architecture

1.2Memory & Storage

1.3Computer Networks, Connections & Protocols

1.4Network Security

1.5Systems Software

1.6Ethical, Legal, Cultural & Environmental Concern

2Computational Thinking, Algorithms and Programming

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson