White space seems like such a small thing, but most good coding practice are small things. They do add up though and can save time.
Here are some common rules about the use of white space. Some have already been mentioned.
- Separate distinct parts of your code with returns. This will act like chapters and paragraphs in written language.
- Use multiple lines to declare variables. I discussed this in an earlier article. Not only is it easier to read all the variables, but if each variable is on its own line, you are able to add a comment describing that variable.
- Place a space before and after an operator. This simply makes the expression easier to read.
- Add spaces between arguments in a function.
- Include spaces between items in an array.
- Separate the three elements in a for loop (after the semicolon) with a space.
- Add a space before the curly braces when declaring a function.
What are your thoughts on using white space in your code?