Tabs vs Spaces



  • This might not belong in Side Bar, but that's my preferred sector of TDWTF, so here I have placed it.

    For indenting in code, I use tabs. I haven't always (I used to use single spaces.) I have no patience for four-space indenting, and I can't understand why anyone does. However, having recently tried using JSLint just for shits and giggles, I found that it had a few options for disregarding certain style conventions, but no option for not harassing me over not using spaces.

    Now, at this point in my career, I use a text editor (Sublime) that pretty much smooths over tabs v spaces, though it sometimes requires some work. Also, when I have worked with others, they are almost never as consistent with tabbing (whether using actual tabs or spaces), so I wind up doing some retabbing pretty much either way.

    However, I still can't wrap my mind around why anyone prefers spaces. So, spaceheads, please regale me with your best reasons to use spaces. I would be surprised if you changed my mind, but I'm certainly open to switching if it can be shown to make sense. Likewise, tabbies, why do you use tabs? I'm not trying to start a flamewar, just trying to get a better understanding of the great tab war--maybe its a non-issue, and I only ever see crazy coders who are way too passionate about it actually argue the point.



  • Use spaces because nobody can agree on what a tab is supposed to represent. (2 spaces? 4 spaces? 8 spaces? Let's call the whole thing off?)

    EDIT: :set et vs :set noet means I don't really need to care strongly either way. Use whatever the previous author used.



  • Spaces are visually more consistent. I have to work on a number of different Windows and Linux operating systems, and tab size is rather random depending on OS and text editor. But 4 spaces are always consistent.

    And because of Python...freaking tabs and spaces. Someone commits a fix, uses a tab when the rest of the file uses spaces, and it blows up on a random assortment of other machines in the office. Even better is multiply-indented blocks that might use a tab followed by four spaces followed by another tab :wtf:. Those are hard to find.

    I prefer spaces because of the first paragraph, but it doesn't really matter as long as it's consistent.



  • @mott555 said:

    Python...tabs...spaces...:wtf:

    The abridged version.



  • My experience: most coders are lazy fuckers who use whatever is the default setting in the IDE.

    So in any kind of tabs vs spaces market research, you can automatically remove 70%-80% of the results and focus on people who care either way.

    The spaces people will always tell you that they can't handle different editors assigning different space sizes to the tab character (2 / 4 / 8). And why the fuck does that matter, when you can simply change the setting to whatever suits you? Because they like to do this:

    int my_function(int      arg1,      // argument 1
                    string   arg2,      // I have a small novel to write about this arg,
                                        // so let's just fall into the next line
                    MyClass  arg3       // So nice to be able to comment everything!
    )  {
         // actual code
    }
    

    You often see this in verbose languages (C++, Java), where projects are huge, and you need to document as much as possible.

    You can't do this with tabs. Any change in the tab width settings will screw up the nice little table they spent 20 minutes crafting.

    But the tabs people don't have the time for that shit anyway. They just want to be able to whip the code around quickly and efficiently. They know better than to try and align anything into vertical columns using tabs. Instead, indentation is always from the left side and mechanical. Eg a single tab for function declaration, another if arguments overflow into the next line etc. No exceptions.

    I'm a tabs guy. But if I wanted to align my code into vertical columns, I'd probably switch to spaces. Pretty simple.



  • Spaces are useful because some people refuse to reconfigure their broken editors to the one true tabstop value of 8.



  • I'm of the ide type. I don't care either way. Shift+alt+f or ctrl+e,d fixes it for me..
    EDIT: meant to reply to cartman2...



  • There is no reason to use spaces.

    Hitting one key (tab) to advance 4 spaces, then having to hit backspace four times to reverse that is a muscle-memory killer. You don't just change the fundamental functionality of the backspace key for just one special case. Nobody's brain can handle that shit.

    @tar said:

    Use spaces because nobody can agree on what a tab is supposed to represent. (2 spaces? 4 spaces? 8 spaces? Let's call the whole thing off?)

    That's the whole point of tab stops. If person A wants them to be 4 spaces, they are happy. If person B wants them to be 8 spaces, they, also, are happy. Yay.

    @mott555 said:

    Spaces are visually more consistent. I have to work on a number of different Windows and Linux operating systems, and tab size is rather random depending on OS and text editor. But 4 spaces are always consistent.

    WTF is wrong with you idiots. Since the tab stops are set by the editor, you can just decide how big you want your tabs to be yourself. Without fucking over other people.

    @cartman82 said:

    My experience: most coders are lazy fuckers who use whatever is the default setting in the IDE.

    So far this is the best answer. The biggest mystery is: why the holy FUCK does Visual Studio default to spaces!?

    @cartman82 said:

    You can't do this with tabs. Any change in the tab width settings will screw up the nice little table they spent 20 minutes crafting.

    We as a society shouldn't cater to idiots.



  • @blakeyrat said:

    WTF is wrong with you idiots. Since the tab stops are set by the editor, you can just decide how big you want your tabs to be yourself. Without fucking over other people.

    I think our official company coding guidelines that nobody reads specifies spaces, so at least here the tab people are Doing It Wrong™.

    Nor do I want to go through on the huge matrix of systems and OS's I work on and tweak all the text editors. Especially since I do so many fresh OS installs for various testing/support purposes.



  • @mott555 said:

    Nor do I want to go through on the huge matrix of systems and OS's I work on and tweak all the text editors. Especially since I do so many fresh OS installs for various testing/support purposes.

    So you're lazy, fine. But don't make your problem everybody else's problem.



  • @blakeyrat said:

    So you're lazy, fine. But don't make your problem everybody else's problem.

    Dear [insert name of any major aerospace corporation here]:

    Due to recent incidents on TDWTF, I must ask you to quit using niche high-performance UNIX-like real-time operating systems on your aircraft because the barebones text editors don't support configuring tab width. You must switch to 64-bit Windows 8 on all systems ASAP or we will not be supporting you anymore.

    That is all.


    ourAnnualRevenue -= $500,000
    competitorAnnualRevenue += $500,000



  • @tar said:

    Use spaces because nobody can agree on what a tab is supposed to represent. (2 spaces? 4 spaces? 8 spaces? Let's call the whole thing off?)
    Use tabs because nobody can agree on how many spaces an indent should be. This way every one can configure their editor as they wish.

    @cartman82 said:

    You can't do this with tabs. Any change in the tab width settings will screw up the nice little table they spent 20 minutes crafting.
    Indent with tabs until it aligns with the line starting the statement, continue with spaces.

    @blakeyrat said:

    Hitting one key (tab) to advance 4 spaces, then having to hit backspace four times to reverse that is a muscle-memory killer.
    I've adapted my muscle-memory to using shift+tab at the start of lines for this very reason. That and because it unindents selected blocks instead of deleting them.

    Other than that I think your post is spot-on.



  • @mott555 said:

    Due to recent incidents on TDWTF, I must ask you to quit using niche high-performance UNIX-like real-time operating systems on your aircraft because the barebones text editors don't support configuring tab width.

    ... and you're typing code directly into that?



  • @blakeyrat said:

    ... and you're typing code directly into that?

    Sometimes, if we need to debug on that platform.



  • @mott555 said:

    Sometimes, if we need to debug on that platform.

    Is "sometimes" an hour every five years? Or three hours every day?

    Because that sounds nightmarish.



  • @cartman82 said:

    You often see this in verbose languages

    I don't know what kind of shit you've been reading but I've never seen any such crap as that.

    @mott555 said:

    freaking tabs and spaces. Someone commits a fix, uses a tab when the rest of the file uses spaces

    Then why you're using Python when that's one of its features. If Python ditched whitespaces for braces you would be nagging about it too.

    I would call for a poll, because I believe the OP is on the minority. I've never worked in a project were tabs were the norm.



  • @Eldelshell said:

    I've never worked in a project were tabs were the norm.

    Me neither, but tabs are still the most logical, rational, usable choice. Which is why the popularity of spaces is so fucking mysterious.



  • @blakeyrat said:

    Is "sometimes" an hour every five years? Or three hours every day?

    Because that sounds nightmarish.

    In my team (application support, a.k.a. working with clueless devs from other companies who are using our stuff) it's fairly common. Someone calls in with a very specific but somewhat obscure operating system and has a problem with our software. Issue is not reproducible on Windows environments, so we have to duplicate their environment, and that often means coding, compiling, and debugging via SSH. And the aerospace industry is full of obscure operating systems.

    So we (well most of us) use spaces and don't even have to think about it.

    @Eldelshell said:

    Then why you're using Python when that's one of its features.

    You'd have to ask the guys who have been working here for years before I arrived. I don't pick the environments.



  • @mott555 said:

    In my team (application support, a.k.a. working with clueless devs from other companies who are using our stuff) it's fairly common.

    "Fairly common" is exactly as vague as "sometimes." GIVE ME A NUMBER PLEASE. I need it to judge whether you're making stupid decisions or not.



  • I guess it has to do with the fact that not all code mangling is done with an editor/IDE and it doesn't look consistent in all of them.



  • @blakeyrat said:

    "Fairly common" is exactly as vague as "sometimes." GIVE ME A NUMBER PLEASE. I need it to judge whether you're making stupid decisions or not.

    2 - 10 incidents a month, maybe more. Probably going to go up an order of magnitude early next year due to a major order that's going through for some brand-new hardware we just finished.



  • @Eldelshell said:

    I don't know what kind of shit you've been reading but I've never seen any such crap as that.

    http://google-styleguide.googlecode.com/svn/trunk/cppguide.html

    Open any important C++ code base, you'll find shit aligned all over the place.



  • @blakeyrat said:

    That's the whole point of tab stops. If person A wants them to be 4 spaces, they are happy. If person B wants them to be 8 spaces, they, also, are happy. Yay.

    It's a nice idea, but AFAICT, it only works for indentation on the left of any characters. If you have a tabular layout like this:

    a   variety of      different   length      words
    and some    more    words       underneath  them
    hey let's   go      nuts        with        this
    

    Then it becomes increasingly sensitive to the tab length used by the original author, and people viewing the code with different tab widths will see different results for how the columns lay themselves out.



  • @Zecc said:

    Hitting one key (tab) to advance 4 spaces, then having to hit backspace four times to reverse that is a muscle-memory killer.

    I've adapted my muscle-memory to using shift+tab at the start of lines for this very reason. That and because it unindents selected blocks instead of deleting them.

    Yah, my editor of choice allows me to use Ctrl+T and Ctrl+D to indent or dedent a line of text one tabstop at a time, and will insert or remove however many spaces or tabs are required to make that happen depening on the spaces-per-indent setting and the use-spaces-or-tabs setting. I'm going to file this under: solved with a sufficiently advanced editor.



  • @tar said:

    If you have a tabular layout like this:

    Why would that be in your code?

    @tar said:

    Yah, my editor of choice allows me to use Ctrl+T and Ctrl+D to indent or dedent a line of text one tabstop at a time, and will insert or remove however many spaces or tabs are required to make that happen depening on the spaces-per-indent setting and the use-spaces-or-tabs setting.

    That doesn't solve the "backspace doesn't work when a code editor is set to spaces" problem. That just introduces more mental overhead to remember the new keyboard shortcuts.

    Computers should behave consistently so my brain can be full of information related to the project I'm working on, not keeping track of 50,000 special-case behaviors.


  • SockDev

    @blakeyrat said:

    That doesn't solve the "backspace doesn't work when a code editor is set to spaces" problem. That just introduces more mental overhead to remember the new keyboard shortcuts.

    still solvable with a sufficiently advanced code editor. all of mine (ViM, sublime, notepad++, Cloud9 IDE, VisualStudio) are set up so that if i hit backspace in a code file and the cursor is currently at a tab stop column, and there are only spaces between the current position and the previous tab stop enough spaces are automatically deleted to bring the cursor back to the previous tab stop.

    in the case of three of them it was the default behavior! (sublime, Cloud9 IDE and VisualStudio (if you select C# developer setting in VS2013, i can't guarantee it will do that for other keybinding layouts or versions))

    spaces are used, but no more effort is required than hitting TAB or BKSPC



  • @blakeyrat said:

    ...tabular...

    Why would that be in your code?

    Yah, wouldn't be in my code, but I have had co-workers who are all over that kind of thing though. I've seen format edit wars raged over it. Effective use of company time, that...



  • @blakeyrat said:

    backspace doesn't work when a code editor is set to spaces

    It is always frustrating if your mental model of what the computer is supposed to do doesn't match what it's actually doing, I'll give you that...



  • @accalia said:

    all of mine (ViM, sublime, notepad++, Cloud9 IDE, VisualStudio) are set up so that if i hit backspace in a code file and the cursor is currently at a tab stop column, and there are only spaces between the current position and the previous tab stop enough spaces are automatically deleted to bring the cursor back to the previous tab stop.

    How do you set up VS to do that? I must know.

    EDIT: wait, you think it does that by default when set to C# mode? It does not.


  • SockDev

    @blakeyrat said:

    EDIT: wait, you think it does that by default when set to C# mode? It does not.

    it did that automatically for me when installing VS2013 and selecting C#, as i said results not guaranteed.

    as for setting it manually i would assume it's under editor preferences, but knowing M$ it's probably not clearly labeled.



  • @accalia said:

    it did that automatically for me when installing VS2013 and selecting C#, as i said results not guaranteed.

    Well I have that exact version of VS, and I selected C# when I set it up and it does not. Since I don't believe Microsoft shipped software that does random shit for one person and not for another, I can only assume you either have some extension that makes it work or changed some setting.

    If ANYBODY knows how to fix that bug in VS, PLEASE let me know, because it will make me get angry at work which is bad. It's already awful enough they require installation of the bloated, useless hunk of shit called "ReSharper." The backspace key not working is going to drive me over the edge.

    EDIT: and by the way, for you people who think I never criticize Microsoft products, whatever this checkbox is in Visual Studio should be called "don't do broken, obviously wrong, shit". THAT IS A CRITICISM OF A MICROSOFT PRODUCT.


  • SockDev

    @blakeyrat said:

    Since I don't believe Microsoft shipped software that does random shit for one person and not for another, I can only assume you either have some extension that makes it work or changed some setting.

    well if it is as you say then colour me surprised. because it did it for me. and i don't have any extensions at all installed at work (i do run resharper at home for my projects)

    you could check under editor preferences and see if there's an option that that makes it work. there probably is. it would be shitty if it's a thing that you have to go to the registry to enable.

    @blakeyrat said:

    It's already awful enough they require installation of the bloated, useless hunk of shit called "ReSharper."

    resharper is really nice, if you're using it from day one. it's not fun to start using it half way through a project (or even worse on a legacy project) and have it spit out 50 bajillion warnings about code style that you have to disable individually, by adding code comments, or globally by turning the warning off.

    if you hate Resharper (and i agree not for everyone) and have to have it installed then why not disable it? you can do that and still say that it's installed.



  • @accalia said:

    if you hate Resharper (and i agree not for everyone) and have to have it installed then why not disable it? you can do that and still say that it's installed.

    I've been turning off its features as they annoy me. It's already like 60% off.

    ReSharper doesn't even appear to do anything VS doesn't already do, except give a few (pedantic dickweed) suggestions on code style, and making the entire IDE (especially intellisense and the MS test runner) run like frozen syrup. I do not get the appeal. But we've had threads on this before.


  • SockDev

    @blakeyrat said:

    I've been turning off its features as they annoy me. It's already like 60% off.

    i expected that, i mean you can turn it completely off so it stops lowing down VS (i've never noticed the slow down, but that might be more noticeable on less than "pure developer juice" machines)



  • @accalia said:

    i expected that, i mean you can turn it completely off so it stops lowing down VS (i've never noticed the slow down, but that might be more noticeable on less than "pure developer juice" machines)

    The machine's fine, the weak point is a 5400 RPM HD, but that has a 4 or 8 GB SSD cache or something like that. It's got 16 GB of RAM, a nice fast CPU, and a GPU capable of easily driving 3 1080p monitors.

    My theory with ReSharper is (most) people who do use it have literally never used VS without it, and have no idea what VS performance is supposed to be like. Of course the huge slowdown is its test runner, which takes approximately 3 times longer than the built-in test runner for reasons I can't even begin to imagine.

    But anyway, the slowdown is minor to the complete destruction of all my muscle-memory. Intellisense works completely differently with it installed. The contextual menus are crapped with useless shit. (Pro-tip developers: contextual menus should contain only operations done frequently.)

    One thing I'll hand ReSharper: it can refactor some stuff better than stock VS. Like if you right click a .cs file in the solution browser, you can refactor the filename and class name all at once, where you have to do 2 operations in VS. That said, I don't do that nearly often enough to be worth wading through the shit.



  • @blakeyrat said:

    you can refactor the filename and class name all at once, where you have to do 2 operations in VS.

    That's always been a single operation, at least in 2008 and 2010. I haven't used anything newer yet.



  • @mott555 said:

    That's always been a single operation, at least in 2008 and 2010.

    From the solution browser?

    ... is there like a vastly different VS2013 that you guys have or something?

    crazypills.png



  • I haven't used 2013 yet. Most of my time is spent in 2008 unfortunately.


  • SockDev

    @blakeyrat said:

    My theory with ReSharper is (most) people who do use it have literally never used VS without it, and have no idea what VS performance is supposed to be like.

    hmm... i'll give you that. if i'm going to use it at all it is installed as soon as i install VS, but since i don't use it at work it's never been installed there.

    @blakeyrat said:

    Of course the huge slowdown is its test runner, which takes approximately 3 times longer than the built-in test runner for reasons I can't even begin to imagine.

    now THAT i'll give you. i have no idea why it does that, or even how. as a result the test runner is disabled if VS test runner is available. (i have ultimate for VS2010 through MSDAA back before i graduated, but VS2012 and 2013 i got through work's MSDN subscription and they only paid for VS premium so the only test runner i have is resharper (also, yes i probably am violating EULA and license but as i never plan to actually release the C# work i do for fun i'm not too bothered. i'll pay for a personal VS license when i do more than fart around because i saw something cool and wanted to try it out. until then i'll just call it out of hours development investigations for work.))



  • Someone tipped me off to the VS Community Edition here a couple weeks ago. It's identical (except in name) to VS Standard. And it'll run all the VS extensions with no restrictions. So you're probably fine license-wise.


  • SockDev

    hmm... well then. that's new.

    next time i wipe my dev VM at home i'll put that on instead.



  • I don't care what your source file has as indents as long as if you use spaces you put some kind of modeline at the end that tells my text editor how many spaces to use.



  • @blakeyrat said:

    Why would that be in your code?



  • My current company has standardized on tabs. Every 6-8 months, some bright spark new employee sends an email "space vs tabs, you guise, what do you think?" The resulting pile on of "standard says tabs use tabs" never ceases to brighten my day.



  • @ben_lubar said:

    how many spaces to use

    four?



  • Most things I've seen default to 8-space tabs. People who write code in languages with lots of indenting tend to use 2-space tabs.

    I use tab tabs.



  • The languages we work in probably have establish norms. I'm not sure I've ever seen a C++ codebase where the indentation wasn't four characters per level.

    It might depend on the language, but I'm going to suggest that if your code is so densely nested that you need to start thinking about having narrower tabs to make space for it, maybe [i]at least consider reducing the level of nesting first[/i]?



  • I prefer to say fuck this, let the tool fix it when there's messy indentation. As a bonus, since the language has a standardized formatter, there's no problem when switching from a codebase I started to a codebase someone else started.



  • @ben_lubar said:

    let the tool fix it

    I've actually thought about that for my personal codes. I was about 96% happy with the results, been meaning to see if I can hackpatch my way to 100% at some point.



  • I've never understood why people use 2-space indents - it's really hard to read.

    Oh, and tabs ftw.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.