• SzethFriendOfNimi@lemmy.world
    link
    fedilink
    arrow-up
    221
    arrow-down
    7
    ·
    edit-2
    8 months ago

    I know it’s a joke but I prefer the tab option. It’s easy to convert tabs to any particular spacing or code point width. It can also vary, if wanted, based on terminal or editor type.

    People with worse eyesight can have a wider indentation while those who choose can opt for something more compact

    • fluckx@lemmy.world
      link
      fedilink
      arrow-up
      58
      arrow-down
      3
      ·
      edit-2
      8 months ago

      Honestly I always preferred tabs for indentation and spaces for aligning. It doesn’t break anyone’s experience. And if somebody wants two spaces for a two-space-tab-width for indentation and other people prefer four. That will work just fine.

      I hate seeing 2 space indents. Unreadable AF ( to me ). At least this way I can easily work in the same codebase without somebody being annoyed ( except for the crying about the tabs )

      • jadero@programming.dev
        link
        fedilink
        arrow-up
        11
        arrow-down
        1
        ·
        8 months ago

        Why not tabs for both indentation and alignment? (Actually, I see indentation as just a specific use of alignment.) Word processors have been doing it for decades (and typewriters for over a century!). Surely we can convince our code processors to use user-definable, fixed position tabs instead of relative position “tab = x spaces”.

        Keeping the [TAB] character in the file then allows everyone the layout they like.

        Or has working solo for 40 years fried my brain?

        • fluckx@lemmy.world
          link
          fedilink
          arrow-up
          7
          ·
          8 months ago

          What I mean with tab = x spaces is only visually and not actually ( there will ( obviously) still be a tab character in my preference. Not sure if that was clear.

          Because alignment are fixed characters compared to indentation. For indentation the only question is how many characters the next indentation needs to be.

          For alignment it is not fixed. As an example of PHP code:

          function test(&obj) {
          $obj->doSomething()
          ....->doSomethingElse()
          }
          
          

          The dots would be spaces because in IDEs people generally use a font where every character is equally wide.

          If I would tab again instead of spaces it could work out if my tab length display is ( for one or more ) adds up to the width of the variable $obj. If somebody else has a tab width of 2 rather than somebody who has 3. It would only align for one of the two people.

          Does make sense? I typed it out after a gym session on my phone.

          Additionally. The whole problem is resolved by using spaces for both alignment and indentation. But in the cursor would still jump one space at a time rather than the whole tab ( although there are keyboard shortcuts for jumping words which would jump all of em.

          I don’t know. Call me old fashioned. I like what I like :/

          • jadero@programming.dev
            link
            fedilink
            arrow-up
            4
            ·
            8 months ago

            If I correctly understand what you are saying, you are describing “relative” tabbing, where /t moves a constant distance from the current position. I prefer “stopped” tabs where /t moves to the next tab stop. If my /t doesn’t create the spacing/alignment I’m after, I just tab to the next position.

            Thus, I would set mine with the first tab position (for indenting) at 1.5 cm and subsequent tab stops at 3, 4, 5, … cm. That way I’d get perfect alignment with both fixed and proportional fonts.

            I’d also set line-wrap or line-continuation to use a hanging indent based on the start position of the line being wrapped or continued.

            I’d also set a boundary between code and comments so that lines always wrapped before the boundary and using the comment character at the end of a line would jump to the other side of the boundary with optional leaders (the characters, usually periods that connect the end/beginning of a gap). In an ideal world, I would be able to “hide code”, pulling all the inline comments into a “hanging indent” structure with their “parent” comments.

            Yes, before the advent of IDE editors and all the fancy intellisense stuff, I used word-processing software for coding. 😀

            • vithigar@lemmy.ca
              link
              fedilink
              arrow-up
              5
              ·
              8 months ago

              If I correctly understand what you are saying

              You did not, but he also picked an example that could be conflated with the 4-spaces issue.

              They’re talking about situations where you might want to align text by a number of spaces that isn’t divisible by your tab size. I’ll expand on their example:

              function test(&obj, &obj2, &a) {
              $obj->doSomething()
              ....->doSomethingElse()
              
              $obj2->doSomething()
              .....->doSomethingElse()
              
              $a->doSomething()
              ..->doSomethingElse()
              }
              

              Again, dots are “visible spaces” in this example, and being used to align chained methods with the length of the object name.

              • jadero@programming.dev
                link
                fedilink
                arrow-up
                4
                ·
                edit-2
                8 months ago

                Edit: Bear with me while I sort out the difference between my display and the resulting code block. Ok, close enough.

                Ok, thanks. I would instead (and prefer to ) do something like this:

                function test(&obj, &obj2, &a) {
                $obj---->doSomething()
                ---->--->doSomethingElse()
                
                $obj2--->doSomething()
                ---->--->doSomethingElse()
                
                $a-->--->doSomething()
                ---->--->doSomethingElse()
                }
                

                In this case, the “>” are showing the tab stops and the “-” the resulting white space. Note how all the calls are lined up. (My preferred alignment style, not necessarily anyone else’s.)

                Yet another edit: I see that I missed addressing alignment on other than tab boundaries. To me, that’s just sinful! 😀

            • fluckx@lemmy.world
              link
              fedilink
              arrow-up
              2
              ·
              edit-2
              8 months ago

              Correct. The way I’m used to it ( and how I thought the world worked ) is that the IDE gives tab a fixed length or characters. If you set it to 4 it would be the equivalent of 4 spaces or 4 letters or whatever.

              If my tab is set to 4 it would take up the width of 4 characters. If I need two indentations I would press tab twice.

              If bob then checks out my code and calls me a maniac and sociopath for using indentation and swears by “2”, the code would just look more condensed. The alignment would still work out because that’s done through spaces.

              var user_name = "Bob"
              var user_age[tab]= "Bob"
              

              This would align the = for Bob, because it needs two characters to align and that’s what his tab width is. It wouldn’t align for me because my tab width is 4. So I would.pur two spaces instead of the . That way it is aligned for everybody regardless of their tab width settings.

              The way you explain it sounds like how tabs works in MS Word ( or other word processors ).

              I don’t think I could work like that. I’ve only ever used IDEs to code ( regardless of how primitive they were back when I started). Interesting take though :D

              • jadero@programming.dev
                link
                fedilink
                arrow-up
                4
                ·
                8 months ago

                The way you explain it sounds like how tabs works in MS Word ( or other word processors ).

                That is exactly how they work, and after 40 years, I still struggle with the whole “tab as a shortcut for spaces” thing. It’s not that I started with word processors, either, just that as soon I started working with them, everything got so much easier for me.

                There are some code-specific things that keep me from just going back to a word processor, but I think our code editors are missing some useful features that are found in word processors.

                • fluckx@lemmy.world
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  8 months ago

                  Generally I’m not very preoccupied with it as the IDE just formats it the way I like it on save :D.

          • azertyfun@sh.itjust.works
            link
            fedilink
            arrow-up
            3
            ·
            8 months ago

            The fact that you had to explain this is the reason why tabs are inferior in practice. People just don’t get it and then in collaborative projects you get a completely misaligned mess because not everyone has the same tab size.

      • fidodo@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        8 months ago

        Yeah, I understood the arguments against using tabs for alignment, but never really got the argument against using them for indentation.

    • kakes@sh.itjust.works
      link
      fedilink
      arrow-up
      43
      arrow-down
      4
      ·
      8 months ago

      I can’t imagine it would be difficult for an IDE to scale the width of spaces found at the start of a line, to emulate this same customization while still preserving my sanity as a fervent space-indenter. I’ve never seen an IDE that does this, but it’d be an interesting compromise.

      • Maestro@kbin.social
        link
        fedilink
        arrow-up
        28
        arrow-down
        1
        ·
        8 months ago

        It’s not difficult at all, and many editors and IDEs already support this, making the entire point moot. Just do whatever the style guide says. I’m into PHP and Python so for me it’s spaces all the way.

        • LaggyKar@programming.dev
          link
          fedilink
          arrow-up
          8
          ·
          8 months ago

          How can it tell the difference between spaces used for indentation and spaces used for alignment, if you use the same character for both?

          • lud@lemm.ee
            link
            fedilink
            arrow-up
            8
            ·
            8 months ago

            I guess the indention sizer thing knows how the formater works and adjusts accordingly. I can’t imagine it would be too much of a problem.

            Iirc Jetbrain IDEs has a feature called dynamic tabs/space (or something like that) which uses exclusively tabs until it needs to align something and a tab doesn’t fit, so it uses a few spaces instead.

          • coloredgrayscale@programming.dev
            link
            fedilink
            arrow-up
            3
            ·
            8 months ago

            Maybe alignment more for the righthand side of assignments. If you have a block of variables with different name lengths, or within a constructor / function call.

          • MotoAsh@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            8 months ago

            All parsers ignore a shitload of whitespace already. Just compare unformatted code, COMPLETELY unformatted code, code without character returns, and it’ll become obvious how any given language is interpreted around whitespace.

            Also fun to see just how infrequent a semicolon is ‘actually’ needed to tell when the end of a statement is here.

      • fidodo@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        8 months ago

        What if instead of having the IDE special case space characters at the start of a line, we had a special character that could represent a variable width space?

          • fidodo@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            8 months ago

            Then you use the variable width space for code indentation, then, when you’re at the code indentation level, you’d switch to spaces for alignment. If the IDE special cased all space characters at the start of the line you wouldn’t have that flexibility. You could also easily create a linter that ensured that the variable width space always has the correct indentation level, and ignore the standard space characters after it.

            • kakes@sh.itjust.works
              link
              fedilink
              arrow-up
              2
              ·
              8 months ago

              You’re entirely correct. Plus, I hate the idea of changing the width of spaces for any reason lol.

    • kureta@lemmy.ml
      link
      fedilink
      arrow-up
      14
      arrow-down
      3
      ·
      8 months ago

      I agree, tabs are better but I have been using spaces for so long I can’t even imagine switching to tabs. also I’d have to reformat all my abandoned projects.