8

I know this topic is tired and this isn't supposed to be a pure "REEEE SPACES BAD" kinda rant but I still don't understand why people would ever use spaces over tabs for indentation. I'm genuinely curious so please give me your arguments in favor of spaces because I just don't understand

So here's my position:
Tabs are objectively better than spaces in every single way
(I know that IDEs also do some of these for spaces, more on that later)
1. They are typed with one key press
2. They can be removed with one keypress
3. They allow for individually configurable width (some people prefer 2 and some 4 width)
4. They take up less memory (kinda irrelevant, but still)
5. You can properly navigate your code using the arrow keys which is much faster than using the mouse while typing
6. You don't have problems with accidentially having one too much or one too little
7. You don't have problems when copy pasting or moving code around (e.g. refactoring)
8. Code is much easier to select with the mouse, and
9. it's much easier clicking the right spot with the mouse where you want to continue typing, which is often at the start of a line

Apart from specific alignment, where spaces are fine (but which also almost never comes up), I just can't see a single thing where spaces are better at. So much so that most IDEs have to *pretend* that they're tabs when typing and removing them. It's so ironic yet people still defend it and big companies still use them.

I feel like I'm going mad 😨

Comments
  • 2
    Playing devil's advocate here:
    1. Spaces can be typed with one key press if you set up your editor.
    2. See 1.
    3. See 1.
    4. Yes, but even in a huge code base it will be kilobytes.
    5. See 1.
    6. I don't see how you can have that problem with spaces and never have it with tabs. Your editor should also assist you with this whether it's tabs or spaces. Is it because spaces appear smaller so differences are harder to spot?
    7. See 6.
    8. Kinda agree with this one but never a problem if you key to the start of the line; this one literally comes down to the clickable area of a tab vs. a space.
    9. See 8.

    So we can collapse your gripes down to:
    1. Have to set up editor and know how to use it when handling space-based indentation.
    2. Prefer code files to take up as little space as possible.
    3. Spaces have a smaller on-screen area so are more difficult to see and click.
  • 2
    I would argue that if you are comfortable with your editor, switching between tabs and spaces should be seamless.

    Disk space for spaces vs. tabs is fairly irrelevant these days.

    Don't use your mouse if you can avoid it, choose an editor that makes it easy to navigate with the keyboard.
  • 1
    I always say: Tabs for indentation. Spaces for outlining. But space people find it hard to understand what the difference is.
  • 0
    @milkybarkid any editor as long as you have a decent keyboard (with home, end, pageup and pagedown in reach)
  • 2
    @milkybarkid Exactly. You can set up your editor to make spaces work like tabs... *BUT WHY*
  • 2
    *THIS IS THE IMPORTANT BIT*

    This is exactly what I'm talking about... Just because you can use an editor that makes using spaces less of a hassle
    *WHY USE THEM IN THE FIRST PLACE IF YOU HAVE TO PRETEND THEY'RE ACTUALLY TABS*
  • 2
    @12bitfloat

    Consider that you could be on a project with 20 other developers, and you all use tabs, which is fine. Developer A could have her tabs displayed as 2 characters wide and pushes a line of code; Developer B has his tabs set to be 8 characters wide. The code appears much different to Developer B and is potentially hard to read due to line length.

    In short, a space is always one character wide.
  • 0
    @12bitfloat

    Also remember that if you use tabs you are limited to aligning tab-wise columns (unless you mix tabs and spaces) vs. using spaces which can align you to any column, potentially making for neater, easier to read code.
  • 0
    @milkybarkid thats why I said tabs is for indentation and spaces for alignment.

    If 8 space tab width is to big then one can change it to two.
    With spaces this possibility doesnt exist.
  • 1
    @milkybarkid personally I have tabs of 3 width for HTML, 2 for Javascript and 4 for CSS.

    PHP is also three and C# is 4.

    When using spaces Im forced to do whatever one person finds nice to read.
  • 0
    @Codex404

    I would say mixing the two is the worst option of all, the ways code formatted like this could appear across a variety of editors would make it look all sorts of weird.
  • 3
    Ok.... as a tab guy let me explain.

    Tabs:
    - its 1 key you have to press.
    - it's "\t" instead of " " in your editor of choice
    - when working with CRLF vs LF tabs can be miss judged by the editor how much white space they actually take up leading to miss alignments.
    - jump on github after using tabs and spaces for a section of code, the tabs generally get out of alignment, makes for reviews being harder.

    Spaces:
    - it's 1 key several times
    - it's a " " instead of a "\t"
    - spaces aren't miss judged by any editor on any OS or platform as for how big they have to be, it's a space, and yes i have seen editors get confused with tabs.
    - reviews are easier to deal with as alignment is always maintained on other systems and platforms.

    Be me:
    - map your fucking tab key to 4* spaces and enjoy all the pros and non of the cons - this takes 2 seconds on any modern editor and you're done.
    - stop this invalid flame war and get on with your devLife, there's more important things to be concerned about.
    - if you're going to be pedantic about the size of your codebase in 2019, especially the minor difference between a couple of bits, maybe you should stop having a indentation fight and minify everything instead.

    * may vary depending on language and coding style of choice.

    -- ok that was a bit passive aggressive, but I haven't had coffee yet and this flame war over tabs and spaces is getting older than the bible.
  • 0
    @milkybarkid Good point, but you could also just make it a mandatory guideline using 2 or 4 width tabs which you would also need when using spaces. But to be honest, code doesn't (or shouldn't) look that different with different tab widths. Only when also using spaces and I would argue that you shouldn't use complicated space relying alignment constructs
  • 1
    @milkybarkid again Tabs for indentation and spaces for alignment nothing looks weird.

    As I said space people dont want to understand it.
  • 1
    @Codex404

    Now that is the key difference between tabbers and spacers: tabbers want to use their editor to format code to what is pleasing to their eye; spacers want their code to look the same to everybody regardless of preference.
  • 0
    @12bitfloat good point? Tab widths are set by the client. Why would men have to say use tabs of size 2?
    Hell if I want to use 69 I am gonna do that. No one has to tell me what size indentation has to be when using tabs.
  • 0
    @C0D4 i agree with the spaces is also one character etc.

    To me the only benefit of tabs over spaces is being free to choose identsize individually.

    Why would other people say what my indentation should look like? Im also not gonna say that everyone has to use Arial 11pt for their editor font?
  • 1
    @Codex404 Companies have all sorts of mandatory code style guidelines
  • 1
    @milkybarkid are you also saying my font should be the same for everyone? What is wrong with using Comic Sans 144pt if I am more productive that way?
  • 0
    @12bitfloat indeed, and I think one should follow them or be fired. But I also think that forcing people to a certain indentation width is counter productive.
  • 2
    @Codex404
    Because as you already said, you break convention for your own pleasure, also for us using tabs can work with a code base using spaces with a minor change without affecting our habits.

    https://www.php-fig.org/psr/psr-2/
    "
    Code MUST use 4 spaces for indenting, not tabs.
    "
  • 0
    I'm not in favor of forcing a common tab width. In fact I'm against it. The only reason it would make sense is so complicated space alignments don't look different for different people but I don't think they should be used in the first place
  • 0
    @C0D4 I follow code guidelines per project. If a project states one thing I will follow it, but that doesnt mean I like it.
    All PHP projects I do have tab indents and its documented that way.
  • 0
    @12bitfloat again (how often do I have to say this)

    Tabs for identation and spaces for alignment and there are no issues. Most editors do these smart tabs by default.
  • 2
    OMG, WW3 has begun...and tabs made from spaces are the best.
  • 0
    @Codex404 🤦‍♂️enforcing a convention that goes against a communal standard doesn't make it right.

    But what ever, do what you will, like this battle of indentation - everyone has already made up their mind before even commenting.
  • 0
    Use search and replace friend, people in the near future will only have thumbs and around eight eyes
  • 0
    @C0D4 are you (ahem) bipolar?
  • 1
    Also, the fake tabs made out of spaces work great when you use backspace but are fucked when you use the del key in most editors

    So fuck spaces
  • 0
    I can be 100% sure you guys have never ever touched a genuine metal olivetti type writer, give me a like if I am not wrong.
  • 0
    @yerdax do you know something my other half doesn't?
  • 1
    @C0D4 I am sure your shadow likes to be behind you
  • 1
    @yerdax i find the light to bright for that, mind you a good dark pair of shades could help 😅
  • 0
  • 0
    Because I programmed Python for years and PEP8 requires the use of 4 spaces per indentation level. You cannot easily mix spaces and tabs in the same source file in Python either. I now prefer spaces over tabs in most of my code. However, I will follow whatever guidelines my employer requires.
  • 1
    @FrodoSwaggins I'm not using the wrong tool for the job. Code navigation with arrow keys (optionally with held control key), home and end keys and holding shift while doing all of that to select. It's super efficient. All of your answers are also exactly what I didn't want people to say: "Yeah but you can make spaces behave like tabs". WHY USE SPACES WHEN I WANT THEM TO BEHAVE LIKE ONE UNIT. I don't care what editor you have, tabs are universal. I also don't know what code reformatting problems they are supposed to generate? They are univeral. One tab = one indentation level. That's it. There's no ambiguity anywhere
  • 0
    4 spaces as tabs -> PSR standard ❤️

    I also had many problems in the past with tab intendation. Code was inconsistent across different editors.

    Never had any of the problems mentioned above. What editors are you guys using?
  • 0
    @FrodoSwaggins I am gonna repeat it once more.
    Tabs are for indenting spaces for alignments. (aka smart tabs)

    So i
    On the next line you tab to the same indentation level and than add x spaces to align it. Thats what smart tabs do.
  • 0
    @irene at least then people have a free choice and are not forced to something uncomfortable.
  • 0
    9 hours later and this is still going
    😂🤦‍♂️😂

    Can we agree to disagree?
    Ps: spaces from tabs ftw!
  • 0
    @irene mixing tabs and spaces is not wrong when done correctly (using smart tabs you dont even notice)
  • 0
    @FrodoSwaggins Tabs do exactly the right thing for indentation. If you'd properly use tabs code can't look fucked up. Guess how many times i've seen fucked up space indented code? More than a few times
  • 0
    My biggest argument against tabs is that they are variable width in non-programming contexts, and if you try to use a file indented by tabs in a dumb program, which you often have to do for various reasons, it goes all weird because of this. (e.g. for troubleshooting on a remote server you might need to use cat or nano because nothing else is available.
  • 0
    I read this the other day:

    https://stackoverflow.blog/2017/06/...

    Even Benjamin hates tabs.
  • 0
    @Demolishun benjamin seems to like tabs since space people supposedly need to enter space multiple times xD
  • 0
    @FrodoSwaggins I can give you an answer very quickly: Read my original rant again. I'm not saying you can't use spaces for indenation. Obviously you can. My point is that they have way more downsides than tabs and virtually no advantages. The argument that they are non-standard width characters also falls flat in my opinion. First because they just aren't "normal characters", they are specifically for indentation, and secondly: Every proper editor supports them properly. Spaces don't have an advantage here either because in order to be able to use spaces without hassle you also need a proper editor. So still no advantages
  • 0
    @Codex404 No, but space people need an IDE that pretends they're using tabs while not actually using tabs
  • 0
    @FrodoSwaggins Then we have very different experiences and I still still can't understand why people would use spaces
  • 0
    @FrodoSwaggins I agree with you, his points are mostly bullshit, though I also dont understand the benefit of spaces over tabs.
  • 1
    I looked at code I had written 5 years ago and posted to github. It had files with fucked up spaces vs tabs in it. I have no idea if the file was originally in tabs and I used spaces, or if the opposite occurred. All I know is if I had used spaces only to begin with it never would have happened.
  • 0
    @FrodoSwaggins can you send me an example? Ive written tons of programs using tabs and work with different indent sizes (2, 3 or 4) and viewing on github shows 8. Never seen any issues with it
  • 0
    @Demolishun as long as you are consistent nothing happens. Using mixed spaces and tabs for indentation is killing.
  • 0
    @FrodoSwaggins I don't understand what you mean with "just look at tab code". It's looks exactly like it should. Properly indented, exactly like if you would use spaces. My problem is that spaces add a bunch of hassle that's unneccessary while providing no benefit to me. My code looks great using tabs, it would look literally the same with spaces
  • 0
    @FrodoSwaggins 4 width is industry standard. Even if you change it it's all relative, nothing is gonna fuck up
  • 0
    @FrodoSwaggins Then I don't know how you indent code
  • 1
    @FrodoSwaggins And weird fucking constructs apparently
Add Comment