Seneca

Maintainability

Computer Science: OCR GCSE, topic 2.3.5

Maintainability

Maintainable code is code that can be read, understood, and fixed by other developers.

Comments

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.
Indentation

Indentation

  • Keeping indentation of code consistent throughout the code is good practice.
  • 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.
  • Consistent indentation makes code easier to read by visualising the scopes involved.
Identifier names

Identifier names

  • Identifier names should be clear about their purpose.
  • For example, which of these two names is clearer:
  • newBalance = oldBalance * INTEREST_RATE;
  • a = b * c;
Code structure

Code structure

  • Code should be well structured through the use of subroutines.
  • Well-structured code allows people to identify a single subroutine that they need to reuse or work on.
Parameters vs global variables

Parameters vs global variables

  • Using parameter passing to move data in a program is good practice, rather than using global variables.
  • Parameter passing stops other subroutines from unexpectedly changing the value of the variables.

Test yourself on Maintainability

  • What does indentation help programmers to visualise?

  • Which of these identifier names are most appropriate?

  • A subroutine receives a value through a global variable instead of through parameter passing. What problem could this cause?

  • A programmer uses the identifiers newBalance and INTEREST_RATE instead of a and b in a bank program. Why does this follow good maintainability practice?

Practise this topic for free