Document Your Decisions

Documenting your decisions is more important for the benefit of others than for yourself. The documentation proves that you made a conscious decision and considered alternatives. That way, when someone else needs to make changes to your code, that person will know why you made the decision you made and also whether it’s possible to safely switch to an alternative solution. Listing 10.13 shows an example of a well-documented decision.

Listing 10.13 Using while instead of for, with Good Documentation

var letters = ['t', 'p', 'i', 'c', 's', 'a', 'v', 'a', 'j'];var currentLetter;// Using a while loop instead of a for loop because the array is modified// inside the loop, and modifying an array ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.