News for hackers. Stuff that matters.
Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @11:40AM (#14595445)
I work on collaborative projects, some use spaces or tabs and it makes no difference to the ease of collaboration. It's just a setting in the .editorconfig.
Re:Tabs, spaces and your salary – how is it really? by Peaker on Tuesday June 20, 2017 @11:43AM (#14595479)
In all collaborative projects I've been that allowed tabs, all files that had been edited by tab users were a mishmash of spaces and tabs that made no single tab width configuration workable. If you chose tab width as 4, some parts of functions would look right, others would have messed up indentation. Ditto for any other tab size.

The theory of tabs for indent and spaces for alignment works. But when collaborating, the practice requires too much support from tooling and too much education for humans -- so it's just not worth the tiny benefit.

Re:Tabs, spaces and your salary – how is it really? by Veedrac on Tuesday June 20, 2017 @11:58AM (#14595636)
That's not a fair comparison. You either disallow tabs, or you disallow spaces. A mismatch isn't either, so it doesn't evidence either being better than the other.
Re:Tabs, spaces and your salary – how is it really? by dxhdr on Tuesday June 20, 2017 @02:35PM (#14597248)
Disallowing spaces isn't an option, you can't align code using tabs. You have to both disallow spaces and enforce a no-alignment (leading-indent-only) formatting style.

Just use spaces! You can't mess it up. ;)

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @02:41PM (#14597299)
Meticulously lining code up like ASCII art seems like an antipattern to me nowadays. It might make some regions of the code look a little bit nicer, but it's never really strictly necessary and it comes at the cost of higher maintenance - for example, add to that list of assignments with lined up equals signs and you have to make your addition line up too, and if your variable name is longer than the longest one in the list so far you have to move all the previous ones over.
Re:Tabs, spaces and your salary – how is it really? by Veedrac on Tuesday June 20, 2017 @03:13PM (#14597563)
> Just use spaces! You can't mess it up. ;)

Oh how I envy someone who can say that.

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @12:50PM (#14596194)
Then just run an autoformatter over the whole codebase once and clean up anything that looks wrong as you come across it later.
Re:Tabs, spaces and your salary – how is it really? by biggieshellz on Tuesday June 20, 2017 @11:51AM (#14595555)
Seems to work OK for the Linux kernel, and the tooling is not onerous -- just run checkpatch.pl on your commits before pushing them upstream.
Re:Tabs, spaces and your salary – how is it really? by user5994461 on Tuesday June 20, 2017 @11:57AM (#14595622)
The kernel has an official & mandatory rule to enforce tabs, at a length of exactly 8 spaces per tab. Anything that doesn't respect that will be rejected without mercy.
Re:Tabs, spaces and your salary – how is it really? by btilly on Tuesday June 20, 2017 @11:52AM (#14595564)
Tabs users frequently claim that.

But when I start running diff, less, and so on, I'm left with the conclusion that every tool has to be configured in a separate way for every user, in every environment. And this makes their code a PITA to deal with.

I'm generally not the one to complain. And I'll still use tabs if that is the standard for the code base that I'm working with. But tabs are strictly worse, and your flippant answer won't particularly please people that you need to collaborate with.

Re:Tabs, spaces and your salary – how is it really? by spinlock on Tuesday June 20, 2017 @12:41PM (#14596101)
This is how I feel about it too. Tab users seem to be saying that, with their configuration of vs-code, tabs work fine. I like a format that works fine with cat, sed, grep, and all of the other unix utilities in my githooks.

plus, I can run vim on a terminal on my phone. vs-code isn't there yet.

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @12:48PM (#14596179)
Exactly what problems are you having with grep/git and tabs? Grep has \s to match any whitespace character and git has settings to ignore whitespace.
Re:Tabs, spaces and your salary – how is it really? by btilly on Tuesday June 20, 2017 @01:39PM (#14596679)
The default display for every tool is 8 spaces for a tabstop. If you don't want that, then each tool has to be configured separately, with a different method for each. Many require a command line option (which one differs by tool) that has to be typed in each time.

Yes, you may not notice or care. But if you're told about why other people don't like it, and dismiss them with flippant answers, you're going to make those other people unhappy.

Remember that the key to successful collaboration is to be strict in what you emit, and generous in what you receive. No matter how unreasonable you think the other is, in this case you're failing as well.

Re:Tabs, spaces and your salary – how is it really? by Sean1708 on Wednesday June 21, 2017 @07:51AM (#14602856)
I don't see the difference between that and having to preprocess every command you run to change the number of spaces used per indentation level (a much harder task).
Re:Tabs, spaces and your salary – how is it really? by btilly on Wednesday June 21, 2017 @10:41AM (#14604173)
Why would you need to change the number of spaces to read it? You probably have a different preference and what you get, but your preference is unlikely to be material to legibility.

Most people have settled with somewhere between 2-4 spaces, and a max of 80-120 character lines. I have an opinion on what I prefer in that range, but I'll live with a variety of stuff. And most others can as well.

Re:Tabs, spaces and your salary – how is it really? by Sean1708 on Wednesday June 21, 2017 @12:34PM (#14605302)
> Why would you need to change the number of spaces to read it?

Yes, why? You were the one that said:

> If you don't want that, then each tool has to be configured separately, with a different method for each.

Re:Tabs, spaces and your salary – how is it really? by btilly on Wednesday June 21, 2017 @01:37PM (#14606049)
There are two reasons for that.

First of all how deeply you go when you align text isn't particularly important. But actually aligning it is super important for it to be readable. It is therefore hard to read a mix of tabs and spaces with the tabstop set wrong.

Secondly while how deep isn't as important, research has found that comprehension drops outside of the range from 2-4 spaces. Therefore the 8 space default that every tool uses for tabs is suboptimal even if you consistently only have tabs everywhere.

The fact that many tools across many environments with many users all have to get it right, and the standard default is bad, makes tabs worse for collaboration.

Re:Tabs, spaces and your salary – how is it really? by runarberg on Tuesday June 20, 2017 @04:04PM (#14598073)
Especially diff. The single thing that annoys me with tabs is the fill behavior. The tab stop is not affected by the leading ‘+’ or ‘-’ in the start of the line which can lead to some weird looking code like :

     function foo() {
    -   if (baz) {
    +   if (bar) {
            baz();
        }
     }
If a tool is not set up to deal with this problem (for example `git config core.pager less -S -x1,5` for a 4 space tab stop, `less -S -x4` makes the first second line above indent with 3 not 4 spaces).

This is also a problem if a line is merged to the line above and an unaware developer leaves a tab character—previously used as indentation—thinking it is a space character. To the developer with the tab-stop set to four there is a one in a four chance they look identical.

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @12:46PM (#14596156)
The indentation style was like that before I got there in each case. One just uses the Visual Studio default settings, the other is default Visual Studio settings but with tabs. I've never run into an issue with diffs or anything like that.
Re:Tabs, spaces and your salary – how is it really? by itaris on Tuesday June 20, 2017 @11:45AM (#14595489)
What do you mean? If some devs are using spaces, and some tabs, wont that create pretty unpleasant whitespace differences?
Re:Tabs, spaces and your salary – how is it really? by lostapathy on Tuesday June 20, 2017 @11:50AM (#14595532)
It does, and it's awful.

In theory it would work out ok. In practice, people use different tab widths, and don't always notice they are "wrong" when doing a quick change. Next thing you know, you've got spacing like your tab width should be 2, 4, and 8 spaces and you really have a mess.

Re:Tabs, spaces and your salary – how is it really? by creepydata on Tuesday June 20, 2017 @08:36PM (#14599729)
>don't always notice they are "wrong" when doing a quick change.

I can't understand this! First thing I do when I open up an editor is show whitespace characters. They are part of the source code this should be always be displayed! It would feel wrong to code without showing whitespace.

If you can see your whitespace you can tell right away that it's wrong.

Re:Tabs, spaces and your salary – how is it really? by thealfreds on Tuesday June 20, 2017 @11:51AM (#14595558)
Pfft I just cmd + alt + j every file I touch. Everyone must conform!
Re:Tabs, spaces and your salary – how is it really? by bryondowd on Tuesday June 20, 2017 @12:19PM (#14595870)
Is this[1] what you're referring to? That sounds like grounds for summary execution to me. My group had me write a git commit hook that demands all source files pass a dry-run of astyle before you can commit. It'll let you view the difference and either cancel the commit and fix it yourself or just take the auto-formatted by astyle version and commit that.

[1] https://kau-boys.com/1128/shortcut/shortcut-of-the-month-ctr...

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @12:42PM (#14596118)
Different teams, not different indentation within the same team.
Re:Tabs, spaces and your salary – how is it really? by passive on Tuesday June 20, 2017 @11:51AM (#14595544)
I'm glad you have a system that works for you and your collaborators. :)

But you've also pointed out a cost to what you are doing. If everyone adopted one or the other, you wouldn't need an .editorconfig setting. You've increased the burden of collaborating with you by requiring a particular configuration setting.

Re:Tabs, spaces and your salary – how is it really? by jimmaswell on Tuesday June 20, 2017 @12:52PM (#14596212)
It's a single file placed at the root of the repository. The text editor/IDE will automatically see it and silently apply it as you edit the file (eg press tab and it inserts x spaces or a tab, uses whatever newline specified). There is no extra burden unless you need to download a plugin for it manually.
Re:Tabs, spaces and your salary – how is it really? by Tyr42 on Tuesday June 20, 2017 @03:26PM (#14597671)
Does ag read it automatically so search results are well formatted? git diff?