These general guidelines are advised regardless of the kind of source code you are working on -
from Ruby to HTML and Objective-C source code or Markdown files, these basic practices should be followed.
The best way to follow these guidelines is by configuring your editor to do all the hard work for you.
- Do not leave trailing whitespaces or line endings on your files:
- On Vim you can add something like
autocmd BufWritePre * :%s/\s\+$//e to your
- On Sublime Text you can just set the
trim_trailing_white_space_on_save option to
- On TextMate, you can install the uber-glory bundle.
- On Atom, ensure that you have the whitespace package installed and its
Remove Trailing Whitespace setting enabled.
- Tab size and indentation: Use 2 spaces instead of hard tabs for indentation.
- On Vim: edit your
~/.vimrc and add
set expandtab and
- On Sublime Text: edit user preferences (⌘ + ,) and set
- On TextMate: everything is pretty much pre-configured with these good defaults (2 spaces, no tabs).
- On Atom, ensure that you have the
Soft Tabs setting enabled and the
Tab Length set to
- Avoid the usage of very large lines, regardless of the line wrap that your editor does, to keep your code
succinct and readable.