• edward@lemmy.ml
    link
    fedilink
    arrow-up
    4
    arrow-down
    1
    ·
    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?

    • StudioLE@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      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

    • 0x00cl@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      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.

    • Vlyn@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      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@lemmy.ml
        link
        fedilink
        arrow-up
        3
        ·
        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.

        • Vlyn@lemmy.ml
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          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.

          • edward@lemmy.ml
            link
            fedilink
            arrow-up
            1
            ·
            1 year ago

            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”.