• I use tabs because I prefer 4-space indents and others might prefer 2-space indentation or the gross and unacceptable 6-space indentation.

    If more than one person is working on a code base, there will likely be more than one preference, and with tabs everyone gets to just set their own tab width.

    Yes, even the 3-space savages.

      •  edward   ( @edward@lemmy.ml ) 
        link
        fedilink
        2
        edit-2
        1 year ago

        Generally aligning stuff isn’t nice. But if you do, it’s tabs up to whatever level of indentation you’re at then spaces the rest of the way. So you wouldn’t have to assume a tab size. And the tabs and spaces have different semantic meaning (indent vs alignment) so mixing them makes sense.

        (Dashes for tabs, * for spaces)

        <form>
        —<input type=“text”
        —*******class=“whatever” />
        </form>
        

        Although really just adding a level of indent is better than aligning.

        <form>
        —<input type=“text”
        ——class=“whatever” />
        </form>
        
      • This is a legit observation. However, I would argue that spaces needs a set indentation width anyway, so if tabs had a set indentation width that coders are expected to maintain when aligning code, it wouldn’t make a difference. Enforcing that in practice may be different, but in theory it works.

  • I’d imagine it’s because people who use spaces are either further in their career in average (because the modern programming ecosystem in general uses tabs so new devs are more likely to only know that) or they’re just more serious about software development because the kind of person to die on that hill is also the kind of person who is very obsessive about other things as well.

    • Wait. Are tabs used more often in modern stuff? Almost everything I use does spaces and I’m not that new to programming. Been doing it for maybe 5 years. I use spaces in everything but Go.

      • Most text editors people use (like VSCode) generally automatically adjust tabs to be whatever the standard indent is for the project (and convert to spaces if it’s necessary). As a result, indenting with tabs usually just works, and so most people just learn to do it that way. Also people are used to using tabs for indent from things like Word which they used before learning to write code. As a result, I’ve noticed most people use the tab key (even if their not technically “using tabs” every time they do it).

        • I think the deeper generational thing is in the idea that anything “just works”. Like I’m a programmer, right, so I know shortcuts. Ctrl+S saves the file, simple right?

          Me when I want to save a file: Ctrl+SSSS. Why? Because I don’t trust it “just works”. Same reason I don’t trust auto save. Same reason I am stunned every time I tell windows to diagnose and fix the network problem and then it actually does.

          I grew up in a time where you couldn’t trust any of that shit.

  •  edward   ( @edward@lemmy.ml ) 
    link
    fedilink
    4
    edit-2
    1 year ago

    Tabs make more sense because that’s exactly what they’re for, indents. Ignoring how it looks, which makes more semantic sense for an indent, <indent character> or <space character><space character>? You wouldn’t use a bunch of spaces to indent a paragraph, so why would you use it to indent code?

    • And by using tabs the IDE can customise whether it’s displayed as two character or four character deep indentation. It just makes so much more sense.

      It’s insane that anyone considered spaces to be a sensible default. Yet I primarily develop in C# where four spaces are the standard so that’s what I use. However the reality is the IDE handles all the formatting automatically so I’m never actually typing four spaces

    • Well, the tab key was created to avoid repeatedly having to press space to create an indentation, but that was on typewritters, so either way, you can use spaces or tab key to indent text.

      Now text editors can transform tab character (‘\t’) to desired amount of spaces, and I think the problem with using tab characters in code (‘\t’) is that system may have different configurations for the amount of space a tab char takes, making it look inconsistent on different systems, while space char is pretty much standard on every system.

    • I was pro tabs when I started out with software development. It just made sense, right? You press the key once, you get a single symbol, you have your indention, neat. And there is the argument that everyone can adjust their tab sizes, want it to be 2 spaces? 4? 6? Whatever? Awesome!

      Then you write actual code and this perception changes. Tabs make a mess, developers often align both code and comments to make sense. That alignment only works at x-spaces and utterly breaks if you change tab width.

      An example in C# with LINQ (just semi-random stuff):

      var test = customers.Where(c => c.Deleted == false
                                   && c.Enabled
                                   && c.HasProducts()
                                   && blockedCustomers.Contains(c.Id) == false);
      

      This kind of indention only works with spaces, not with tabs. And no, mixing tabs and spaces doesn’t work (like some users claim, that you can indent with tabs and then do alignment with spaces… nope, if you change tab with then your space alignment breaks).

      Honestly, I don’t care either way, I just use what my company uses and adapt. But till now it has always been spaces (even though I was team tabs in university) and now I actually prefer spaces as it just makes sense. It’s consistent, it’s easy, it works everywhere.

      Btw. the Lemmy code editor is shit, trying to align this was trial and error for a minute :-/

      •  edward   ( @edward@lemmy.ml ) 
        link
        fedilink
        2
        edit-2
        1 year ago

        if you change tab with then your space alignment breaks

        No, it doesn’t? Here’s the exact same text content with different tab widths:

        The tabs are smaller but the spaces are the same, so the alignment remains.

        • Ah, I see what you mean, out of instinct I’d have put one more tab on the “whatever” line, which would break the concept. But if you manually do both the indent + alignment in spaces then it works.

          Besides your IDE of choice screaming at you that you are mixing tabs and spaces that is :)

          It still feels like a hack though, simply going with spaces is more uniform and works everywhere. Especially as a lot of code is viewed in browsers nowadays (GitHub, GitLab, …) and tabs are often a mess in those environments.

          • Besides your IDE of choice screaming at you that you are mixing tabs and spaces that is

            JetBrains IDEs actually have it built in, it’s called “smart tabs”.

  • So the two camps are:

    spaces: who want to be able to have accidental fractional indentation and so they can force anyone who may read their code in the future to see the indentation at the size that they intended.

    tabs: who want consistent bug-resistant and logical formatting, and for any future reader to decided for themselves thier own personal best indentation size.

    A possible explanation: people who want it their way at the expense of others are more likely to choose spaces, and are more likely to feel at home at a company that does exactly that in order to extract more profit from thier victi… customers.