Writing error-free codeDocumenting code

When writing programs, code should be as legible and error free as possible. Debugging helps keep code free of errors and documenting helps keep code clear enough to read.

Part ofComputer ScienceProgramming

Documenting code

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

When we 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 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, the program.