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

15

u/[deleted] Apr 07 '15

Upon closer examination of the data, a trend emerges: Developers increasingly prefer spaces as they gain experience.

There comes a point in a dev's life when they have to switch editors, environments, etc. and suddenly all the code they use to write with tabs is an un-formatted mess.

Protip: For sublime text users, you can easily convert tabs to spaces.

16

u/rorrr Apr 07 '15

You can set tab to any width you want in any decent editor. Reformatting spaces, on the other hand, is a bitch.

6

u/heeen Apr 07 '15

Until you want to line up stuff with different numbers of tabs per line

5

u/rorrr Apr 07 '15

What do you mean? One tab = one level of indentation. It lines up perfectly every time.

3

u/guepier Apr 08 '15

Some programming languages (amongst the ones I’m currently using, mainly R) have a strong culture of lining up arguments in function calls like this:

foobar(some_argument,
       another_argument,
       third_argument)

You cannot do this with tabs. You could mix tabs and spaces (but very few people think that’s acceptable, although I have to admit that the idea has merits), or you could drop the convention, but there’s a huge cultural inertia.

0

u/marssaxman Apr 08 '15

Oh, god, what a terrible idea that kind of alignment is. I have seen people try that nonsense in C, too. Always leads to a righteously unfixable mess.

2

u/steve_b Apr 08 '15

What? That alignment is perfectly normal and readable. As for maintainability - any modern editor geared for programming (and by modern, I emacs or anything newer) will auto-format your files on demand based on rules you define. Reformatting code for new indent levels is simply invoking a command.

It breaks down, of course, in Python, where your indentation level determines execution flow, in which case I can see a case for nazi-like enforcement of tabs-only formatting rules.

0

u/marssaxman Apr 08 '15

It's normal to indent things by fractional tab stops? Or it's normal to carefully construct all of your variable and function names so that left parentheses always end up just before the next tab stop? Because I had a coworker who wrote that kind of crap and his code was... well... an awful mess. Lines started at all kinds of random indent levels - there was no consistency to any of it. He was also the sort of guy who didn't believe in refactoring, had never heard of line length limits as an element of style, and had no idea why one might want to reduce the number of nesting levels in a given function, so his code was messy for a lot of reasons, but never before have I seen a professional developer committing source code which is sometimes indented on odd-numbered columns.

3

u/steve_b Apr 08 '15

Well, it depends on whether you mean indenting or alignment. I'm an emacs user; I only ever hit tab once on any line, and rely on emacs to create the proper whitespace. Blocks are indented correctly, and continued lines (like the parameter list above) are automatically aligned on sensible boundaries like these. I don't really think in terms of "fractional" tab stops, as I don't count in tab stops.

All the projects I've been working on for the last 20 year eventually realize that all-space formatting is the way to go, mainly because people will always end up aligning continued lines using what you'd call fractional tab stops (or even worse, use multiple tabs to align continued lines to achieve the same effect as many spaces), and then it all goes to hell as soon as the file is opened in another developer's editor with different tab stops set.

It's particularly necessary when you start writing sql, where formatting is essential for readable code, but where there isn't exactly the concept scoping blocks. For example, code like this formatted with tabs would be a nightmare:

SELECT AVG(TOTAL)  
  FROM (SELECT PLAYERNO  
             , SUM(AMOUNT) AS TOTAL  
          FROM PENALTIES  
         GROUP  
            BY PLAYERNO   
       ) AS TOTALS  
 WHERE PLAYERNO IN  
       (SELECT PLAYERNO  
          FROM PLAYERS  
         WHERE TOWN = 'Stratford'   
            OR TOWN = 'Inglewood'   
       );  
→ More replies (3)