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.
codeInstructions in a computer program. that is hard to read makes it difficult to understand what the programSequences of instructions for a computer. is trying to do. It also makes it difficult to understand the purpose of any variableA memory location within a computer program where values are stored., procedureA section of computer code that performs a specific task. and functionA section of code that, when programming, can be called by another part of the program with the purpose of returning one single value.. Errors are easier to fix when we understand the code we are reading through.
When we documentingMaking code easier to understand by giving meaningful names for variables, procedures and functions and by adding comments to explain the purpose of instructions. 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
How to document code
Documenting code is very straightforward. It involves:
giving meaningful names for variables, procedures and functions
placing commentingAdding one or more sentences to explain the purpose of a section of code. 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, debugThe process of finding and correcting programming errors. the program.