If anyone can post a sizable production code base that uses tabs that DOESN'T look like shit with a different tab width, I'm certainly open to being proven wrong.
Here and there's the problem. Too many people with editors that go round replacing N spaces with tabs everywhere to have sane alignment in a code base with >1 developer...
I do it myself but it requires a bit of maintenance and I wouldn't trust teammates with it. There will always be some guys who don't understand the idea and mess everything up.
In a team environment, now, I wouldn't chose anything but 4 spaces. Speaking from experience.
- with anything but 2, 4 or 8 spaces, some guys with incorrectly set up editors will mess everything up.
- tabs don't work well for alignment, and as long as you allow the tab character, someone will make a mess.
- 2 spaces is not enough to properly distinguish between blocks.
- 8 spaces can look very nice if your code is very clean. It won't be the case of your project.
Notice there are a couple examples in that code where multiline method calls are meant to line up, and if tabs are not set to 8 they don't line up.
Also, most people who do have several years of experience under their belt will tell you: don't align. Mid-line alignment is a waste of a maintainer's time to have to update alignment blocks every time you add/remove variables... and statement-alignment is unreadable[1].
[1] https://github.com/pennersr/django-allauth/blob/a44134688f5b...
The crux of the issue is poor tooling. Aligning correctly is a pain because most editors suck terribly at it. For instance neither emacs nor vim align correctly when using tabs by default (they use as many tabs as they can and then pad using spaces, instead of indenting only with tabs and aligning only with spaces). If they did it would be painless to indent and re-indent.
When some of the most venerable code editors out there can't even seem to get it right I think there's no point in fighting it. Learn to stop worrying and love the space, I know I did. Or alternatively use a language like go which provides a standard tool to indent everything, make it mandatory pre-commit and never look back.
But I never found a single editor that handles spaces correctly. I currently use vscode with vim bindings and whenever I deal with a space-indented codebase I want to tear my hair out: I inconsistently have to hit backspace sometimes once, sometimes multiple times to get rid of an indent level in insert mode. And don't get me started with yaml, a really painful experience to edit it.
On a large code base with multiple committers, I've never seen this rule followed consistently. In fact, I think this shows a poor engineering decision: "Let's make a rule where everything looks OK 95% of the time, except when you change tab widths (which is, presumably, why we made the rule in the first place.)"
I believe older versions of Xcode did that by default with objc (maybe still; didn't check lately) if you press enter in the middle of a function argument list. Really annoying.
If you try this, it fails for people who use a different tab size than you, which is the whole supposed point of using tabs.
But yes, the correct answer is don't align. Utter waste of time.
If it fails, then you have not understood and you are not using your tools correctly. If your alignment depends on tab width, then you are not using tabs for indentation and spaces for alignment, you are using tabs for indentation and alignment and spaces for alignment, which of course breaks when you change your tab width.
The other thing you need to do is stop people from checking in code that doesn't follow project conventions.
https://github.com/ioquatix/rack-freeze/issues/2 https://github.com/ioquatix/latinum/pull/1
>deliberately have my editor set up to change tab width based on editor width (responsive indentation width)
What editor are you using that has this setting?
Firstly, I've explored using responsive tab width in https://github.com/ioquatix/jquery-syntax which is nice when presenting code on a mobile phone.
Secondly, I've got hard coded tab width on my desktop with a huge screen vs my laptop with a smaller screen, and this works for all editors, including my primary editors Atom and vim.
Finally, I've played around with using responsive CSS within Atom, but due to recent changes in the text rendering my current CSS doesn't appear to be working.
Trivially easy to set up your editor correctly once (if you even need to) and now everyone gets their preferred intenting size