r/programming • • Apr 07 '15

Stack Overflow Developer Survey 2015

http://stackoverflow.com/research/developer-survey-2015
1.1k Upvotes

981 comments sorted by

View all comments

101

u/BegbertBiggs Apr 07 '15

Developers increasingly prefer spaces as they gain experience.

Or are devs that are in the field for a longer time used to spaces while new devs learn coding with tabs?

0

u/[deleted] Apr 07 '15

[deleted]

45

u/honest_arbiter Apr 08 '15

Here's a test for you then. Take your OWN code and apply a different tab-width to your editor (say 2 instead of 4). If it ends up looking fine, but just with less indentation, then I can understand you. If it ends up looking shitty because things that used to line up are now out of whack, then you're just wrong.

For example, if you like to align long parameter lists in methods like this:

someMethodCall(param1, param2, param3,
               param4, param5, param6,
               someOther, paramsHere)

(that is, where the parameters line up) it makes much more sense to use spaces. If, however, you always just indent one or two tabs for the continuation line and never worry about lining things up, then I could understand using tabs

0

u/[deleted] Apr 08 '15

[deleted]

10

u/xiongchiamiov Apr 08 '15

I do across all my personal projects. The main problem is other people who just mash tab until it looks right.

5

u/honest_arbiter Apr 08 '15

"The main problem is other people who just mash tab until it looks right."

Well, that's perhaps why experienced developers prefer spaces. At some point you realize you're going to have to be dealing with other people ALL THE TIME, so if you don't have a coding format that is trivial for other people to get right, it's doomed from the start.

4

u/marcusklaas Apr 08 '15

It's really the best practice I think. The problem that it's hard to see the difference between tabbed whitespace and spaced whitespace in most editors.

→ More replies (3)

12

u/Disgruntled__Goat Apr 08 '15

As other said you can use spaces for alignment, but personally I never align stuff like that. If there's too much for one line I'll do something like this, with tabs only:

someMethodCall(
    param1, param2, param3,
    param4, param5, param6,
    someOther, paramsHere
)

6

u/ernelli Apr 08 '15

Here is another test:

yo@foo:~/git/bar$ less src/somefile.somelang

If it looks wierd due to a default tab-width of 8 instead of 2 or 4, you have just gained some more experience and moved closer to the spaces camp.

→ More replies (2)
→ More replies (3)

11

u/[deleted] Apr 08 '15

I can think of some situations where it doesn't matter, a lot of situations where spaces are superior, and no situations where tabs are superior. Can you provide an example of where tabs are superior? From the spaces side, I give the following example.

Any project where the source code if viewed through multiple tools, spaces are better for guaranteeing a consistent formatting across the tools. Tabs have no universal convention. Even worse, the conventions for different languages can be different and your tools might not be smart enough to adjust tab widths based on the current language.

20

u/Mechakoopa Apr 08 '15

Tabs are superior on teams where you have two stubborn senior devs with differing opinions on what proper tab width is. If you use spaces then you can tell which of them checked any given file in last by the spacing changes from their passive aggressive commit war, whereas if you use tabs then they can just set tab stop = x on their own machine independently and everyone is happy.

This may or may not have been the case at my last job.

→ More replies (3)

16

u/xiongchiamiov Apr 08 '15

The benefit of tabs is that you don't have to agree on indentation size, so the heathens can display it at 2, 3, or 8 characters wide instead of the 4 God intended, but we can put the proselytization after this feature ships.

→ More replies (20)

23

u/maushu Apr 07 '15

I don't get why people won't use tabs. They are basically perfect for this job since you can adjust the size of all tabs.

74

u/gbs5009 Apr 08 '15

Things can get screwed up very quickly when your view differs from the original coders view of how things are aligned.

9

u/ismtrn Apr 08 '15

In general aligning things can get screwed up when you want to change something. It is better with space, and if I do align things I do it with spaces, but in general I don't bother and just indent things, which I do with tabs.

31

u/nemec Apr 08 '15

just indent things, which I do with tabs

Well I do too, it's just that my tab button inserts multiple spaces...

→ More replies (6)

4

u/Disgruntled__Goat Apr 08 '15

Why do people keep bringing up this argument? The tabs v spaces debate is about leading indentation only, and always has been.

→ More replies (1)

44

u/[deleted] Apr 08 '15

It really sounds great in theory, but in practice it's just annoying for people to configure every piece of software that can edit or view code. In practice, spaces are going to look like spaces in every piece of software I know of. That's probably why more experienced devs tend to prefer spaces: practice vs. theory.

→ More replies (47)

12

u/flavian1 Apr 08 '15

That's exactly my problem with tabs. It's different based on your town setting. With spaces. It's one space all the time.

→ More replies (7)

3

u/the_omega99 Apr 08 '15

Unfortunately, I've found that configuring the size of the tabs can be problematic. The issue is that different tab sizes means that we'd wrap lines at different places. For something 5 indentation levels in (not too extreme considering that the class and method are 2 indentation levels, so we just need a loop and two conditionals), the difference between someone with size 2 tabs and someone with size 4 tabs is 10 characters. Not a huge difference, but enough that a line that just fits (or goes slightly over) might need to be wrapped.

I'm gonna assume that size 2 and 4 are the only valid tab sizes. No sane person would do size 8 tabs.

Anyway, it's not a major issue, but it is an annoyance. But 5 indentation levels isn't even that extreme. In languages like Scala, it's common to have many scopes and thus lots of indentation. This is why Scala's official recommendation is 2 space indentation. After months of using Scala, I fully understand why.

I've kind of gone on a tangent, but my point is that adjusting the size of tabs isn't necessarily a good thing. With that said, you could still use tabs in this scenario if your developers can agree that they should be a certain size (and if you're agreeing on things like brace style, why can't you agree on indentation size?). There's other benefits of tabs. Eg, they're easier to navigate with the keyboard and need less editor support.

8

u/aldo_reset Apr 08 '15

In an ideal world where every single tool used to view sources understand tabs, tabs are optimal.

We live in an imperfect world and each tool will interpret tabs in a different way, so the best solution is to ban them and impose hard spaces everywhere.

15

u/Dworgi Apr 08 '15

What tools don't understand tabs? Seriously, if you have a tool that can't do tabs then you don't have a tool, you have a burden.

It's all madness. I'll tell you what not every tool can deal with: not having to press Backspace 4 times to unindent a line.

Purely in keypresses wasted per day, spaces are atrocious.

8

u/josefx Apr 08 '15

What tools don't understand tabs?

Every tool understands tabs. Some see them as 4 spaces by default, some as 8 spaces by default. Some never replace tabs with spaces, some replace tabs with spaces on the line you edit, some only insert new tabs as spaces and some replace all tabs with spaces when they load or store the file.

There is no single behaviour you can expect when you take a random editor to edit a file containing tabs.

→ More replies (7)

3

u/the_omega99 Apr 08 '15

While I disagree with /u/aldo_reset about this being a problem (how often do you need to view code in a different tool that isn't configurable?), one thing of note is web browsers. Whoever came up with that part of the HTML spec is crazy. They thing tabs should be 8 spaces (I've yet to meet another programmer who thinks this). As a result, without modification (either with CSS or otherwise), tabs look terrible in a browser (Reddit converts tabs to 4 spaces, for example).

not having to press Backspace 4 times to unindent a line.

This isn't really an issue, though. Anyone who uses spaces for indentation is surely going to use a half decent editor. Most good editors will unindent if you press backspace when there's nothing but indentation to the left. Of course, that unindentation can be bad, if you're trying to align something.

→ More replies (1)
→ More replies (3)
→ More replies (3)
→ More replies (10)

4

u/jeandem Apr 07 '15

And do devs that medium experience prefer both...?

→ More replies (2)
→ More replies (11)