You can get around those issues by having an editor at lets you configure how it interprets the tab key. I use Komodo which lets me set a global setting, per-language setting, and even per-file setting.
1 tab unless I run into something that uses something different than I’ll adapt so the next person looking at it doesn’t have to deal with inconsistency.
In regards to the why, I’m not really sure, its just what I’ve been using since I’ve began programming and hasn’t been an issue. Although, hitting tab once is less prone to error than multiple space bar taps or tab taps. Though those types of error won’t result in breaking code just formatting, so yeah.
I have the bulk of code indented by six spaces, then each block is indented by 4 spaces, in the editor that I use when you have any { } blocks it indents then, I prefer to have the opening { on the same line as the preceding code:
eg:
if ($something === $somethingelse) {
// do this
}
//rest of code
I just use whatever the editor in question uses… by default for the current one i’m using, that’s an additional indent of 2 spaces per depth of braces.
I still use vim, and that is set to translate tab to 4 spaces.
I rarely share code, but if I do I run it through a beautifier first because I am pretty slapdash about what gets indented for my own selfish reasons.
I have been ridiculously inconsistent over the years and tend to adopt the style prevalent in the code base/libs I am working on, rather than bite the bullet and re-arrange the whole thing. Not in the tab=4spaces thing, but whether they are 1 or 2 tab indenteded.
The reason for this, rather than having a pre-set indent at 2 spaces, is that it still allows other devs, or even myself, to specify the width of the indent.