I know the general answer to "How should I indent my code" is generally "do as you wish but do it the same way as everyone on your team", but in the last time I've seen many projects and platforms relying on a 2-space indentation.
I just want to make sure I get the "best bang for my buck" when indenting and make sure it's future-proof. Changing the structure in a project later on is a pretty big problem considering compatibility, etc.
Most projects now rely on 2 Spaces, 4 Spaces or Tabs.
Projects and their indentation:
- tabs
- WordPress
- jQuery
- CakePHP
- Git
- Linux Kernel (doesn't seem to be consistent)
- 4 spaces
- Django
- Symfony
- Stackoverflow
- Zend Framework
- Yahoo
- MacVim
- Memcached
- 2 spaces
- HTML5 Boilerplate
- Ruby on Rails
- Drupal
- Node.js
- Github
- Blueprint-Css
- Jekyll
- Chosen
- backbone.js
- Modernizr
- Scriptaculous
- Clojure
- Facebook (I think)
The question is where is the "community" going? 2 Spaces or 4 Spaces?
My guess is 2 Spaces, since it manifests itself in the big companies and all the standards-pushing projects are using it.
What do you think of the current and future situation? Is it wise to adapt 2 Spaces indentation?
We indent with TABS at our organization for one simple reason. Tab's can be converted to spaces, but spaces cannot be converted to tabs (reliably). Once you get the hang of it most editors let you set the TAB-WIDTH, so you can see the code as indented as you would like. 2, 4, 6 spaces!
来源:https://stackoverflow.com/questions/7070927/is-it-safe-to-indent-with-2-spaces