Are you saying there’s a tool that will let me work with (superior) tabs but have standards compliant commits?
I’ve tried doing this in my .gitconfig with limited success. It didn’t work consistently.
Are you saying there’s a tool that will let me work with (superior) tabs but have standards compliant commits?
I’ve tried doing this in my .gitconfig with limited success. It didn’t work consistently.
In a perfect world each language has exactly one (non-configurable) formatter and this solves all the formatting discussions.
For JS I use prettier and altough I am not 100% happy with some of the formatting choices I _love_ it because I can focus on code and not have flamewars about tabs vs spaces with my co-workers. prettier ends all style discussions. And code reviews are much nicer because people concentrate on checking the code, not the formatting.
The only arguments I hear for spaces are alignment (I don't have time to give a shit about such minor aesthetic preferences) and forcing other people to see code a certain way (I really don't understand why I would want to force my editing preferences on others). I don't think either one of them justifies the annoyance of spaces.
i say tabs are superior. the real solution is probably variable width tabstops: http://nickgravgaard.com/elastic-tabstops/
The only editor that really does properly support "just set this option and then it's like you are using tabs" is Atom. But I don't really want to use Atom.
If you use an autoformatter there is no need to manually check for misalignement!
Just type in some code, press a key and everything is aligned, problem solved!
Indentation all fucked up? No problem, press the auto format key, and the computer will unfuck it for you.
Need to indent or unindent a block of code? No problem, press the auto format key. You don't even have to think about whether it needs more indentation, or less. The computer will do that for you.
Do you type all your code on one line without putting any spaces in? Well, don't tell anybody, just press the auto format key, and they will never find out. (I know I just told you not to tell anybody, but: I do this all the time. And it's great.)
In fact, you don't need to really think about any of this whatsoever even at this level of detail, because you can just develop the habit of pressing the reformat key every now and again. Or get the editor to do it every time you save, and then you don't even have to remember to do that.
But, however you do it, this sort of tool reduces to pretty much zero the amount of energy you have to expend on caring about how the code looks.
As a concrete example (for JS projects), you could configure Prettier to use tabs for indentation:
https://prettier.io/docs/en/options.html#tabs
Then you could use eslint-plugin-prettier, which fails lint if the code isn't Prettier-formatted and makes ESLint autofix also run Prettier:
https://github.com/prettier/eslint-plugin-prettier
Then set up lint to run in CI alongside tests.
There are configurations for your editor that will allow this, independent of the EditorConfig project.
My opinion on this is that it's a bad idea in the age where we (finally) have near universal acceptance of source control, because they bloat commits with irrelevant changes in surrounding lines to preserve alignment when identifiers change. Black got it exactly right - optimize for readability and change locality.
If you feel like it’s useful, you should probably be using an editor with real elastic tabstops instead.
You picked the wrong vocation my friend. It's "brittle and fiddly" all the way down.
re "you should probably be using an editor with real elastic tabstops" ... i don't get what you're trying to say. What does real or fake elastic tabstops have to do with the choice to align code beyond just indentation?
I think there’s a chicken-and-egg situation with monospaced type and programming. Programming was a thing before digital proportional typefaces were a thing, so some people came to rely on the fixed spacing to treat their source code as a 2d grid rather than a 1d buffer. This in turn made it more difficult to switch over to proportional typefaces despite their advantages, and at some point code == monospaced was just taken for granted. Another issue that comes from mistaking your code for a 2d mosaic is the dogma of dictating a maximum number of characters per line, instead of the more reasonable approach of using whatever expresses the structure of the program most clearly, and relying on line wrapping to make sure it’s all visible.
FWIW I use proportional fonts, and 95% of the time it’s completely unproblematic. Fortunately I rarely work with code that uses manual alignment. It’s usually the occasional ASCII diagram that forces me to temporarily switch over to fixed pitch.
what's the argument against this? There are many arguments for how it can improve readability and speed up understanding of what you're looking at when you're not familiar with it.
If you are in a system small enough that you only ever have to look at code in a code editor, then this anti-feature won't be a real problem.
If you work in a sufficiently complex environment that displays code across a variety of platforms, tabs will only make working with the code more difficult.
One odd exception is GitHub which inexplicably uses size-8 tabs by default which is way too big. I can only assume that somebody there is a space zealot and wants to screw up the UX for enlightened tab users.
When I have to work on N platforms that are constantly shifting, I don't want to spend the overhead and mental effort to reconfigure the ones that can be reconfigured, and eat nameless dread on the ones that can't.
When you view code across dozens of platforms, across dozens of machines, your perspective on "high maintenance config" everywhere changes a bit.
If you can't be effective with default configs, you lose efficiency to config maintenance.
Really, the last thing I want to deal with while I'm triaging some critical issue is dependency management for N code viewers.
http://blog.gngcreative.com/wp-content/uploads/2015/02/mi0fg...
Those metal things you can see there, those are tabstops. They are called tabstops because when you press the tab key, the carriage mechanically stops at the tabstop.
Tabstops were placed every 8 characters. A tabstop is simply a way to "type" 8 spaces with one keypress.
Github is not the only page that uses 8 spaces for a tab, and it's definitely not inexplicable. The Unix/Linux terminal uses 8 spaces by default if you insert a tab. Vim uses 8 spaces by default if you insert a tab. Python considers a tab to be equivalent to 8 spaces. I'm sure there are a lot of other systems that default to this value.
If you want to control how an indentation looks, use spaces. If you want tabs because the size is configurable and can be adjusted to one's preferences, you can't at the same time complain about "unreasonable configurations" that others use :)
tabstops were _not_ restricted to 8 characters. In many systems different tabstops were different widths from their predecessor. E.g. your first tabstop might be 20 characters in but all the ones after it would be 8 past their predecessor. Alternately you could vary all of them but that'd look pretty weird.
This can be very neat for responsive design: use tabs for your indentation, and then on large screens use `tab-size: 4` because you’ve got space to spare and four is generally superior to two, and on narrow screens use `tab-size: 2` because you don’t have as much width to play with.
root = true
[*]
indent_style = tab
indent_size = 2
That being said, GitHub's default setting can only be seen as a spaces mongering ploy to subvert the true usage of tabs.This is all pretty pretty straightforward to configure on a per-repo basis too, so you can hop around multiple projects with different standards and not have to think too much about this.
Yes. It's an autoformatter and it will make you never care again about tabs and spaces and other unimportant issues us devs love to bicker about. Focus on the higher level stuff instead :)