White space enhances readability by making the individual components of statements stand out.
Using space around the assignment character provides a strong visual cue separating the left and right hand sides of a statement. Using space around the binary logical operators can clarify complicated expressions.
simpleSum = firstTerm+secondTerm;This practice is controversial. Some believe that it enhances readability.
simpleAverage = (firstTerm + secondTerm) / two;1 : nIterationsThese spaces can enhance readability. Some programmers leave them out to avoid split lines.
foo(alpha, beta, gamma)foo(alpha,beta,gamma)Spacing enhances readability.
if (pi>1); disp(‘Yes’); endThis practice helps to distinguish keywords from functions.
Enhance readability by introducing white space between logical units of a block.
One approach is to use three blank lines. By making the space larger than space within a block, the blocks will stand out within the file. Another approach is to use the comment symbol followed by a repeated character such as * or -.
Code alignment can make split expressions easier to read and understand. This layout can also help to reveal errors.
weightedPopulation = (doctorWeight * nDoctors) + … (lawyerWeight * nLawyers) + … (chiefWeight * nChiefs );