Documenting code

Code that is hard to read makes it difficult to understand what the program is trying to do. It also makes it difficult to understand the purpose of any variables, procedures and functions. Errors are easier to fix when we understand the code we are reading through.

When we document code, we make it easier to read and understand. We also document code in case:

  • we need to come back to it at a later date
  • someone else needs to change or fix it
Comments are used in programming to add clarity to code. These will let anybody using the program know exactly how it works and any improvements needed.

How to document code

Documenting code is very straightforward. It involves:

  • giving meaningful names for variables, procedures and functions
  • placing comments within the code to explain the purpose of each step

Having properly documented code makes it much easier for a programmer to understand and, if necessary, debug the program.