• xigoi@lemmy.sdf.org
    link
    fedilink
    arrow-up
    73
    arrow-down
    23
    ·
    1 year ago

    Tabs let you define how big you want each indent to be

    …except when they don’t. Many common environments have a hardcoded tab size of 8, which is insanely big for using it for indentation.

    • z3bra@lemmy.sdf.org
      link
      fedilink
      arrow-up
      51
      arrow-down
      9
      ·
      1 year ago

      Because other people might have restricted environment which might not suit their preference is not a good reason to level it down IMO.

      Also, I think 9 is the best size for indent (matter of preference), do you think I should switch to space so everyone can enjoy this wonderful view I have ?

    • kevincox
      link
      fedilink
      arrow-up
      21
      arrow-down
      1
      ·
      1 year ago

      What environment are you using that has a hardcoded tab size? I haven’t seen this since typewriters.

      Some projects just use tabs as a compressed form of 8 spaces. But that is a sin. Use tab to mean “one indent level” and align with spaces if you need to. (the occasional ASCII art diagram)

      • xigoi@lemmy.sdf.org
        link
        fedilink
        arrow-up
        13
        arrow-down
        5
        ·
        1 year ago

        What environment are you using that has a hardcoded tab size?

        • Termux
        • SourceHut
        • “View page source” in the browser
        • kevincox
          link
          fedilink
          arrow-up
          14
          ·
          edit-2
          1 year ago

          Termux

          I think running tabs -N (where N is you preferred tab size) in the terminal should work. This is what I use in my zshrc on desktop.

          SourceHut

          Yup, they seem to be pretty opinionated here. If you look at the source there is just an inlined style with a single rule pre { tab-size: 8 }. I guess that is what you get when you use opinionated tools. The user’s browser isn’t right, my preference is right!

          “View page source” in the browser

          On Firefox this uses my default tab size of 4. But I guess changing this default isn’t user-friendly.

          • JackbyDev@programming.dev
            link
            fedilink
            English
            arrow-up
            3
            arrow-down
            1
            ·
            1 year ago

            You can’t count it as good when it is unconfigurable when it happens to use your preference when the whole selling point of tabs is that they’re configurable.

            • kevincox
              link
              fedilink
              arrow-up
              3
              ·
              1 year ago

              I don’t understand what you are trying to say. I agree that SourceHut forcing their preference isn’t good. The other two are configurable and I have configured them to my preference on my machines.

              • JackbyDev@programming.dev
                link
                fedilink
                English
                arrow-up
                2
                arrow-down
                1
                ·
                1 year ago

                You made it sound like Firefox wasn’t configurable, my bad. I thought you were saying you didn’t care that it wasn’t configurable because you liked the width they chose.

                • kevincox
                  link
                  fedilink
                  arrow-up
                  4
                  ·
                  1 year ago

                  Oh no. It is configurable, although it requires editing userContent.css. So barely configurable. I think it defaults to 8 but I reduce it to 4.

              • ck_@discuss.tchncs.de
                link
                fedilink
                arrow-up
                1
                arrow-down
                1
                ·
                1 year ago

                I agree that SourceHut forcing their preference isn’t good.

                I don’t think this is a fair point. Every developer makes “opinionated” decisions on default settings on a daily basis. SourceHut is open source and anyone can propose a patch that makes the tab width configurable, which to my knowledge has not happened. “Forcing their preferences” would imo imply that this discussion happened and the patch was rejected without good reason.

                To me, this sounds a lot like the usual “I don’t like the how this thing that you provide for me for free is doing this one thing so I demand you change it for me free of charge” argument.

      • Faresh
        link
        fedilink
        English
        arrow-up
        6
        arrow-down
        3
        ·
        1 year ago

        What environment are you using that has a hardcoded tab size?

        Microsoft Windows’ Notepad. I have sometimes used that when on a public computer.

    • IRQBreaker@startrek.website
      link
      fedilink
      arrow-up
      13
      ·
      1 year ago

      As an embedded software developer that does linux kernel drivers I’ve come to love the tab size 8 indentation level.

      I’m paraphrasing: “if your indentation level gets too deep, it’s time to rethink/refactor your function.”

      And with tab 8 you’ll notice it rather quick if your function does too much/unrelated stuff.

      A function should be short and do one thing only, if possible. It also makes unit testing easier if that’s a requirement.

      • xigoi@lemmy.sdf.org
        link
        fedilink
        arrow-up
        5
        arrow-down
        6
        ·
        1 year ago

        When you’re operating on such a low level of abstraction, it’s no wonder you don’t need deep nesting.

        • IRQBreaker@startrek.website
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          Oh, I’ve done my fair share of C++ and Python as well. But you got to agree with me that when you are on your fourth indented “if case” it’s time to step back and think about what you are trying to achieve. I mean it’s probably going to work, but probably also very hard to maintain that type of code.

          • xigoi@lemmy.sdf.org
            link
            fedilink
            arrow-up
            3
            arrow-down
            1
            ·
            1 year ago

            How would you implement, for example, Gaussian elimination with at most 3 levels of nesting?

                • JesperZ@programming.dev
                  link
                  fedilink
                  arrow-up
                  3
                  ·
                  edit-2
                  1 year ago

                  There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination.

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      11
      arrow-down
      1
      ·
      1 year ago

      This is the biggest problem with tabs. Too many tools don’t let you adjust the size (or make it very difficult). This is the only reason I usually prefer spaces (only very slightly).

      My dream solution is elastic tabstops and I’ve posted about it here before a few months ago. The problem with wanting elastic tabstops is that it seriously compounds the issue of “editors don’t properly support it”

      https://nickgravgaard.com/elastic-tabstops/

  • zygo_histo_morpheus@programming.dev
    link
    fedilink
    arrow-up
    42
    arrow-down
    4
    ·
    1 year ago

    Another accessibility reason for tabs: when using a braille display, each space takes up one character cell, so indenting with four spaces eats up four cells. Indenting three times with four spaces each eats up 12 characters already. Tabs only take one character cell each, so three indents = three character cells used.

    The fact that there (I assume?) isn’t a braille oriented text editor that can handle space-based indentation in a smarter way is a bit depressing. Maybe the solution should be better tools based around accessibility rather than convincing everyone to switch to tabs, which is a project that will just never succeed.

    • atheken@programming.dev
      link
      fedilink
      arrow-up
      16
      arrow-down
      4
      ·
      1 year ago

      So your fix is “convince all the people that want/need the better handling to use a specific editor?” - perhaps it’s a smaller number of people, but do you not see the irony there?

      I honestly don’t care about tabs vs. spaces, but if there’s a low cost change in my setup that makes it easier on others, why not?

      • zygo_histo_morpheus@programming.dev
        link
        fedilink
        arrow-up
        17
        arrow-down
        2
        ·
        1 year ago

        My spontaneous reaction is that making some sort of braille oriented setting for some or hopefully most editors used by people with braille displays (I have no idea if using a “normal” editor even makes sense if you’re using a braille display) is the most pragmatic solution to their screens being taking up by spaces.

        First of all, convincing everyone to use tabs is a monumental task. Convincing people with braille displays to use more convenient tools on the other hand seems pretty easy, why wouldn’t you want to use more convenient tools?

        Secondly, there is a large amount of code written with spaces today, so even if people switch with tabs in the future you might still want to be able to read legacy code.

        Thirdly, I don’t think that the choice of tabs vs. spaces is completely arbitrary because of alignment. Using tabs for indentation and space for alignment leads to a lot more micro management of whitespace compared to just using spaces. I would guess that alignment isn’t very braille friendly anyway, but it does make the code more readable for other people. Having a good braille editor affordance might be closer to letting us have our cake and eat it too.

        Of course, I don’t know what this would look like exactly, and maybe there’s some sort of obstacle that I’m overlooking, I do want to be clear that this is just of the top of my head as someone who has never used a braille display.

        • atheken@programming.dev
          link
          fedilink
          arrow-up
          6
          arrow-down
          6
          ·
          1 year ago

          There’s a difference between doing something that’s “easier” and what’s right.

          Whether there is more legacy code with spaces or tabs is irrelevant. Most of the code that will be written hasn’t been written yet.

          I disagree with you on “micromanagement” of spaces vs. tabs, that is nonsense. Set up a formatter for commits and set your IDE to display how you want.

          The pragmatic view on one or the other is that for a one group of people, using tabs appears to be significantly better, and for everyone else, it barely matters at all, except as personal preference.

          That being said, I’m not vision impaired, so I don’t know what the preference would be.

          The reason we’re even talking about it is that someone that has studied it from an accessibility perspective has asserted that tabs would be preferred.

          • zygo_histo_morpheus@programming.dev
            link
            fedilink
            arrow-up
            7
            arrow-down
            1
            ·
            1 year ago

            There’s a difference between doing something that’s “easier” and what’s right.

            The way I see it, there are two competing strategies for improving the experience for braille screen users: making tabs more widely used and improving braille oriented editors. Without knowing for sure, my guess is that improving editors is a better strategy and this is in part because it is easier.

            As a matter of principle it might be “more right” for people without visual disabilities to adjust themselves to people with visual disabilities than vice versa, but I also think that it’s important to care about what is actually likely to improve braille screen users experience and not default to the more principled goal without any consideration for how realistic it is.

            (Of course, I might be overestimating how easy it is to get better braille oriented editors, but since you referred to this as the “easy” solution it doesn’t sound like you’re disputing this specifically.)

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

              Of course, I might be overestimating how easy it is to get better braille oriented editors

              A braille display traditionally is a personal, almost handfitted (estimated by price) device controlled by its screen reader software. Not the editor. This has some unfortunate implications:

              • There is no (standardized) API to control your braille device directly. You could hand your screenreader filtered data, but that would be read as well. At best, you might be able to script your screen reader software to a varying degree of success. However:
                • Every aspect about this is extremely abysmal in every possible way, so it will likely require you to fork over some biiiiig amount of cash to one of the vendors to provide a brittle plugin. In particular if we are talking about JAWS. Think of extremely unstandardized COBOL dev with less stability and more price gauging involved.
                • As far as free readers are involved, only the proprietary and licensing aspect go away. Still, developing extensions is terrible in many ways. For example, for ORCA, I was able to find out that you can extend it somehow. Alledgedly. NVDA on the other hand has better documentation. That is to say, it has documentation. Now, you might recall that NVDA is written mostly in Python, and its devs rightly don’t even pretend that one could develop stable software in Python, so APIs might change. However, I wasn’t able to find a Filter function specific to braille output. That’s likely because
              • From my superficial experience, developers of screen readers think of braille displays mostly as an alternative to speech. It even took them quite a while to be smart about not displaying redundant, long lines of text.

              So yes, you might be overestimating how easy that is, compared to telling some diva asswipe chucklefuck to use that formatter or work at McDolans.

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

                Thank you for the insight, didn’t expect it to be that dire. Tabs and spaces nonwithstanding, hope that the screen reader/braille display tooling situation improves in the future, sounds like it is sorely needed.

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

                  I sure hope so, but I’m not overly optimistic tbh. The market is basically considered medical, therapeutic devices. It is as you imagine, probably worse. It isn’t easy to find prices directly, but the only way this range of vendors continues to exist in this niche market is to sell devices with the complexity of a keyboard for four to five digits. There is no competition worth talking about happening.

                  So unless very specific regulation takes place, I don’t see standardized access to braille displays happening.

            • atheken@programming.dev
              link
              fedilink
              arrow-up
              4
              arrow-down
              4
              ·
              1 year ago

              Let’s agree that we aren’t going to affect this change in this comment thread, so which one is more “pragmatic” is beside the point.

              What does matter is whether we decide to have an inclusive view on this issue, and are willing to make extremely minor modifications to our settings and workflows to be more accommodating for others.

              I am encountering more and more cases where people behave in inexplicably selfish ways, and this just feels like another one. It’s low/no-cost to do, yet could yield benefits to others. Low cost/risk, high potential reward.

              Starting with “we’re not going to even consider raising awareness and let the market decide” is just a very cynical way to approach the world, and I’d argue is even actively harmful to the people that hold that view.

              • zygo_histo_morpheus@programming.dev
                link
                fedilink
                arrow-up
                4
                arrow-down
                1
                ·
                edit-2
                1 year ago

                Do you think it matters if getting a large number of people to switch to tabs is an achievable project at all? Maybe I am a bit cynical but this seems to me like something that is actually very difficult to do.

                When faced with a problem like this I think it makes more sense to approach it from a perspective of what would be a practical way to actually address it and refusing to do that does I think in its own way betray a different kind of cynicism.

                For the record what I’m saying isn’t that I wouldn’t switch to tabs for the sake of people with various disabilities, I’m saying that spaces are slightly better than tabs if you don’t have any relevant disabilities so if there is a way to have the cake and eat it to that would be a nice bonus, but that’s honestly besides the point.

                • atheken@programming.dev
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  1 year ago

                  You are treating this as a binary/zero-sum game. Will we get to 100% use of tabs (or spaces)? No. Will we get a “perfect” viewer made and then adopted by all visually-impaired people? No. Making people aware that a fairly mundane choice has a negative impact on others might change their behavior, or at least challenge it.

                  Change like this is incremental, so just having the conversation, and asking you to consider that making a small change to your config might help some people down stream is something. Asking you to bring this point to the next conversation about tabs vs. spaces, is helpful.

                  I’m saying that spaces are slightly better than tabs if you don’t have any relevant disabilities

                  This is my fundamental issue with your original statements, and this thread: It’s a subjective choice that you think is slightly better than removing a barrier/major annoyance for an entire group of people that may want or need to interact with your code. It’s closing the door on possibility for a minor personal preference.

    • ck_@discuss.tchncs.de
      link
      fedilink
      arrow-up
      10
      arrow-down
      3
      ·
      1 year ago

      rather than convincing everyone to switch to tabs, which is a project that will just never succeed.

      Few years back, Coraline Ada Ehmke went on a one person crusade opening a pull request on every major Github repository to adopt a code of conduct for the project, detailing the complex rules of how the humans in that microcosm of a project should interact with one another. Today, it’s the norm.

      Arguing that it’s invincible to convince people at large to adopt tabs over spaces with good arguments is a ridiculous statement. All you are doing is making up excuses for not having to care.

      • TheCee@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        That reminds me of those times when back on reddit some dev showed up to present their new GUI library. Bragging about how they were better than Qt devs etc. (even though they didn’t implement the hard parts, like working text fields or tables)

        After some time a bunch of people had enough and started bullying those guys into submission about accessibility. After some time, every of those toolkits had support or at least plans for supporting screenreaders. Eventually, AccessKit became a thing.

        Good times.

      • zygo_histo_morpheus@programming.dev
        link
        fedilink
        arrow-up
        4
        arrow-down
        3
        ·
        1 year ago

        Arguing that it’s invincible to convince people at large to adopt tabs over spaces with good arguments is a ridiculous statement

        I do actually think that it is very hard to convince basically every programmer of something, no matter how good arguments you have.

        Also, without knowing much about the issue, it sounds a bit like the tooling for people using braille displays isn’t very good and fixing that is maybe also worth advocating for, perhaps it’s even a strategy for advocacy that is more effective?

    • pexavc@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Yeah. It is depressing.

      I’ve always wanted an accessibility feature that uses haptic feedback to mimic braille patterns for reading purposes too.

      In general a lot of creative stuff can be done if we focused on it even a tiny bit more.

  • eee@lemm.ee
    link
    fedilink
    arrow-up
    39
    arrow-down
    1
    ·
    1 year ago

    Neither tabs or spaces are good. The correct way is to leave no whitespace in the code at all. It’s unnecessary and adds to processing time.

    Everyone should aim for 1LOC per commit

  • corytheboyd@kbin.social
    link
    fedilink
    arrow-up
    40
    arrow-down
    4
    ·
    1 year ago

    I wish every language had a gofmt, this is such a non-debate (tabs are indentation, spaces are alignment)

    • _stranger_@lemmy.world
      link
      fedilink
      arrow-up
      7
      arrow-down
      2
      ·
      edit-2
      1 year ago

      Holy wars are fun, but this is the answer.

      At least this way the holy war takes place in commits to change the formatting file.

      Unless go, in which case the holy war is now everyone who hates go format rewriting the code in a different language.

  • z3bra@lemmy.sdf.org
    link
    fedilink
    arrow-up
    42
    arrow-down
    11
    ·
    1 year ago

    Tabs for indent, spaces for alignment. This is the way, I can’t believe people are still fighting that ?

    • realharo@lemm.ee
      link
      fedilink
      arrow-up
      31
      arrow-down
      2
      ·
      edit-2
      1 year ago

      Anything for indent (barely matters, as long as the editor forces it to stay consistent), and fuck alignment, just put things on a new line.

      • z3bra@lemmy.sdf.org
        link
        fedilink
        arrow-up
        19
        arrow-down
        3
        ·
        edit-2
        1 year ago
        struct Ident arr = [
        {
        .id
        = 0,
        .name
        = "Bob",
        .pubkey
        = "",
        .privkey
        = ""
        },
        {
        .id
        = 1,
        .name
        = "Alice",
        .pubkey
        = "",
        .privkey
        = ""
        }
        ];
        
        • realharo@lemm.ee
          link
          fedilink
          arrow-up
          18
          arrow-down
          1
          ·
          edit-2
          1 year ago

          Not like that, lol

          Just saying, instead of this monstrosity

          CreateOrderRequest(user,
                             productDetails,
                             pricingCalculator,
                             order => order.internalNumber)
          

          Just use

          CreateOrderRequest(
              user,
              ...
          

          Putting the first argument on a separate line.

          Same if you have an if using a bunch of and (one condition per line, first one on a new line instead of same line as the if) and similar situations.

          • Lmaydev@programming.dev
            link
            fedilink
            arrow-up
            9
            arrow-down
            1
            ·
            1 year ago

            People seem to have a real issue with using new lines and I’ve never quite understod why.

            It feels like a lot of those people are using notepad like applications instead of coding focused ones with collapsible regions etc.

          • z3bra@lemmy.sdf.org
            link
            fedilink
            arrow-up
            7
            arrow-down
            1
            ·
            edit-2
            1 year ago

            When I talk about alignment it’s not about function arguments, but values, “=” signs and such. You simply cannot use tabs for that because alignment must be fixed and indentation independent:

            CreateOrderRequest(
                user,
                productDetails     => order.detail,
                pricingCalculator  => DEFAULT_CALCULATOR,
                order              => order.internalNumber)
            
            • realharo@lemm.ee
              link
              fedilink
              arrow-up
              10
              ·
              edit-2
              1 year ago

              I normally avoid that too, I find it hurts readability more than helps, plus a proper IDE will separate it with color anyway.

              But yeah, the newline comment doesn’t apply to this.

              • z3bra@lemmy.sdf.org
                link
                fedilink
                arrow-up
                1
                ·
                1 year ago

                To each their own indeed. But my rule of thumb is: only use tabs when there’s no other character before it (aka, start of line).

            • PHLAK@lemmy.world
              link
              fedilink
              English
              arrow-up
              6
              ·
              1 year ago

              This kind of “manual” alignment should be avoided for many reasons including the fact that adding/removing/changing of one parameter here may force you to modify multiple lines which on it’s own is annoying but this will also show up in the diff during review making it harder to grep what was actually changed.

              • z3bra@lemmy.sdf.org
                link
                fedilink
                arrow-up
                2
                ·
                1 year ago

                I personally favor code readability over patch readability. But I reckon this is a matter of preference so I can understand how you might not like that.

            • catastrophicblues@lemmy.ca
              link
              fedilink
              arrow-up
              4
              ·
              1 year ago

              Yeah I agree I don’t find alignment very useful. It’s more work for dubious benefit, and god forbid you change one of the lines.

      • milo128@lemm.ee
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        1 year ago

        seconded on not aligning things. its the whole source of the problem in the first place and doesnt even serve a purpose

        • MajorHavoc@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          It does help with reducing thrashing between edits in git diffs. Or rather, opinionated autoformatters do, which is the only reason I bother with alignment.

    • GuybrushThreepwo0d@programming.dev
      link
      fedilink
      arrow-up
      9
      ·
      1 year ago

      I used to think this way, at least when writing C++. But it’s objectively harder to do and convince other people to follow, especially if they can’t be bothered to change their environment to display tabs and spaces differently. It’s a losing battle so now I just do spaces when working with other people

      • KIM_JONG@lemmy.world
        link
        fedilink
        arrow-up
        3
        arrow-down
        4
        ·
        1 year ago

        Always do spaces, because you can never trust how someone else has their tab configured.

        How is this even a debate anymore. I thought we all agreed on this years ago.

        • Pyro@lemmy.world
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 year ago

          you can never trust how someone else has their tab configured

          Why on earth would I care how someone else has their editor configured? It’s none of my business, and none of yours either.

          • azertyfun@sh.itjust.works
            link
            fedilink
            arrow-up
            2
            ·
            edit-2
            1 year ago

            Because other people are fucking morons and their editor doesn’t have visible whitespace enabled - or it does but they don’t give a shit.

            Therefore these fucking morons have anywhere between 2 and 8 spaces-per-tab configured and will happily mash the tab key however many times is convenient for them to align their code or comments because they don’t understand shit about fuck when it comes to alignement (or they don’t care). Now I open their file and everything is predictably misaligned. Spaces and tabs are mixed from one line to the next, and in particularly egregious cases no tab width I can locally set on the file will make it readable because multiple different morons used different tab widths to align with tabs - sometimes within the same goddamn function or comment.

            Have you ever tried to read an important technical diagram in ASCII art aligned with tabs by different people with different IDE settings? Because I have. Emphasis on tried.

            • Pyro@lemmy.world
              link
              fedilink
              English
              arrow-up
              2
              ·
              1 year ago

              Spaces and tabs are mixed from one line to the next

              This is a solved problem: Enforce linting before committing using something like Git Hooks / Husky.

              Have you ever tried to read an important technical diagram in ASCII art aligned with tabs by different people with different IDE settings?

              No, because we live in the present and use proper tools for diagrams. SVG diagrams tend to be common nowadays. I’m aware you can’t read them raw, but realistically the intersection between people who need to read important technical diagrams and people who don’t have access to a web browser is vanishingly small (dare I say nonexistent?)

              • azertyfun@sh.itjust.works
                link
                fedilink
                arrow-up
                1
                ·
                1 year ago

                Tell me you develop with modern languages without telling me you develop with modern languages.

                Try linting perl, or bash.

                Like yeah if you work on a modern JS/Python/C# project, whatever, whitespace is going to be autoformatted, so the tabs vs spaces debate does not matter AT ALL.

                • Pyro@lemmy.world
                  link
                  fedilink
                  English
                  arrow-up
                  2
                  ·
                  1 year ago

                  Tell me you develop with modern languages without telling me you develop with modern languages.

                  You say this like it’s a bad thing?

                  Try linting perl, or bash.

                  If you’re already writing Perl/Bash scripts then it would probably not take you long to write a git hook to check the beginning of each line of source to check if there’s a space or a tab character and preventing the commit if the wrong one is found. Crude and far from perfect, but still better than nothing.

                  if you work on a modern JS/Python/C# project, whatever, whitespace is going to be autoformatted, so the tabs vs spaces debate does not matter AT ALL.

                  It does though. If you read the original article then you’d know that the advantage of tabs is that everyone can choose exactly how deep their tabstops are, which is an objective benefit over spaces.

    • AnyOldName3@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      1 year ago

      I’ve yet to find tooling that supports this. Clang format has a setting that looks like it does it, but actually does something else. If I have to press the spacebar a bunch of times each time I add an argument to a function, that’s a pain, and it’s a bigger pain to convince the people I’m working with that that pain’s less bad than using spaces everywhere and having the IDE deal with it.

      Until the people making editors and auto formatters acknowledge that the obvious most sensible whitespace style is even a thing, I’m forced to do something else and be really grumpy about it.

      • z3bra@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I understand your point of view. Personally I either copy the previous line and replace the arguments there, or insert X number of space using the repetition feature of my editor. It also has a feature that will align multiple cursors together with the “farthest” one using space, which is a killer feature for me! (See this presentation video @1:40).

    • zygo_histo_morpheus@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      1 year ago

      It’s hard to do this consistently (especially in a team) because people might (and statistically in a large enough project, will) use the tab key for alignment since it’s faster than pressing space, or just be confused about what whitespace is tabs and what is space. Just using space everywhere is idiot proof and requires no work to micromanage. The only way to use tabs is to not align at all.

      • z3bra@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I agree that it’s hard, but not impossible. This usually boils down to how Nazi people are when merging code. In a corporate environment, nobody gives a damn so yeah you gotta use whatever you want because there are already different indentation systems within the same file anyway :)

        But hey, you gotta live by the changes you want to see happen, so I personally put a lot of effort in formatting my code regardless.

    • zagaberoo@beehaw.org
      link
      fedilink
      arrow-up
      8
      arrow-down
      5
      ·
      1 year ago

      Then you lose the benefit of tabs: you can’t adjust the tab width without destroying alignment. So you end up with a confusing mix of characters for no benefit.

      Mixing them is the worst option.

      • Faresh
        link
        fedilink
        English
        arrow-up
        5
        ·
        edit-2
        1 year ago

        The opposite is true, though. If you use tabs for indentation and spaces for alignment, you can adjust the tab width without destroying alignment. That’s the big benefit of the tabs-for-indentation-spaces-for-alignment mix.

        You can’t do that with only tab characters, you can’t even align stuff with tabs because it has variable width.

      • z3bra@lemmy.sdf.org
        link
        fedilink
        arrow-up
        4
        arrow-down
        1
        ·
        1 year ago

        You might not understand how to do it properly so here’s the idea:

        Tabs will let you reach the indentation level of the current block, then from here, you’ll use spaces to align stuff property. Here’s an example, where >••• are tabs (I’m exaggerating alignment for the sake of the example) :

        >•••if (condition1 == true
        >••• || condition2 != false)
        >•••{
        >•••>•••struct ident people[] = [
        >•••>•••>•••{
        >•••>•••>•••>•••.name   = "bob",
        >•••>•••>•••>•••.pubkey = "value1",
        >•••>•••>•••},
        >•••>•••>•••{
        >•••>•••>•••>•••.name   = "alice",
        >•••>•••>•••>•••.pubkey = "value2",
        >•••>•••>•••}
        >•••>•••];
        >•••>•••secureConnection(people[0].name, people[0].pubkey,
        >•••>•••                 people[1].name, people[1].pubkey,
        >•••>•••                 CRYPTO_ALGO_DEFAULT);
        >•••}
        

        As you can see, everything will stay correctly aligned as long as it’s within the same block.

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

        You’re confusing using tabs for indentation and spaces for alignment with using tabs and spaces for indentation. This means each line starts with tabs. Next you optionally have spaces for alignment with previous lines. Then you have content (like code or comments). Because you never have a tab following a space the alignment is never destroyed by adjusting how wide a tabstop is.

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

            That example is using tabs for both indentation and alignment. The article you linked even says not using tabs for alignment is a solution.

            • Do not use tabs for alignment. In such case given example should look like:
            fun foo x =
            --->let val abs = if x > 0
            --->              then x
            --->              else -x
            --->in
            --->--->(* ... *)
            --->end
            
            • zagaberoo@beehaw.org
              link
              fedilink
              arrow-up
              1
              arrow-down
              1
              ·
              1 year ago

              Yes, but keep reading. That strategy is a pain to maintain especially across editors.

              • JackbyDev@programming.dev
                link
                fedilink
                English
                arrow-up
                1
                ·
                1 year ago

                Many styles are difficult to maintain, I’m not saying it is or isn’t. I’m saying that using only spaces for alignment will not let your alignment get messed up with various tabstops settings.

  • stevecrox@kbin.social
    link
    fedilink
    arrow-up
    24
    arrow-down
    2
    ·
    edit-2
    1 year ago

    Years ago there was no way to share IDE settings between developers.

    You ended up with some developers choosing a tab width of 2 spaces, some choosing 4 spaces and as there was no linting enforcement some people using 2-4 spaces depending on their IDE settings.

    This resulted in an unreadable mess as stuff was idented to all sorts of random levels.

    It doesn’t matter if you use tabs or spaces as long as only one type is consistently used within a project.

    Spaces tends to win because inevitably there are times you need to use spaces and so its difficult to ensure a project only uses tabs for identation.

    IDE’s support converting tabs into spaces based on tab width and code formatting will ensure correct indentation. You can now have centralised IDE settings so everyone gets the same setup.

    Honestly 99% of people don’t care about formatting (they only care when consistency isn’t enforced and code is hard to read), there is always one person who wants a 60 charracter line width or only tabs or double new lined parathensis. Who then sucks up huge amounts of the team time arguing their thing is a must while they code in emacs, unlike the rest of the team using an actual ide.

    • FlagonOfMe@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      4
      arrow-down
      4
      ·
      1 year ago

      inevitably there are times you need to use spaces

      When? You indent with tabs then add any spaces you want for precise alignment. When would you need to use spaces to indent?

      • stevecrox@kbin.social
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        1 year ago

        Do not mix tabs and spaces.

        Its impossible to automate checking that tabs were only used for indentation and spacing for precise alignment. So you then take on a burden of manually checking

        You end up with the issue where someone didn’t realise and space idented or anouther person used tabs for precise alignment and people forget to check the whitespace characters in review and it ends up going inconsistent and becoming a huge pile of technical debt to fix.

        Use only one, you can automate enforcement and ensure the code renders consistency.

  • darq@kbin.social
    link
    fedilink
    arrow-up
    27
    arrow-down
    8
    ·
    1 year ago

    I’ve always wondered why some people tout “forcing a consistent appearance across environments” as a pro for spaces. That’s a bad thing.

    To be honest I’m surprised code format converters aren’t ubiquitous. Let the repo have it’s master format, enforced on commit. Then converters translate into each developer’s preferred standard dialect on checkout and back again on commit.

    • exscape@kbin.social
      link
      fedilink
      arrow-up
      11
      arrow-down
      3
      ·
      1 year ago

      The consistent appearance thing is probably more about how mixing tabs (for indentation) and spaces (for alignment, eg in multi-line function definitions of calls) looks like complete crap if you change the tab width.

      • kevincox
        link
        fedilink
        arrow-up
        8
        arrow-down
        1
        ·
        1 year ago

        I think you have it backwards. If you use tabs for indentation and spaces for alignment it works great for any tab size.

        It is when you use a tab just as a compressed representation of 8 spaces and use them for alignment as well that it goes to shit. (because you have made the sin of tab == 8 spaces instead of the correct tab = 1 indent level)

        • exscape@kbin.social
          link
          fedilink
          arrow-up
          4
          arrow-down
          4
          ·
          1 year ago

          How does that work, and with which editor settings? If you simply set the tab width (tabstop) in vim, things go south.

          Say you have a function definition one indent level in, then 22 characters of text. You more want to align the next line to that. How does that work in practice with tabs?

          The obvious way with tabs and ts=4 would be 6 tabs and two spaces(one tab for the initial indent, the rest to match 22 characters). But then someone with ts=2 comes along and barely gets half way there, or someone with ts=8 who overshoots by a lot.

          • wolo@lemmy.blahaj.zone
            link
            fedilink
            English
            arrow-up
            6
            arrow-down
            1
            ·
            1 year ago

            That’s not how you should mix tabs and spaces for alignment. You use the same number of tabs as the previous line, and then fill the remaining width with spaces. That way, when you change tab width, the alignment spaces will always start in the same column as the line they’re aligning to, regardless of the tab width.

            • exscape@kbin.social
              link
              fedilink
              arrow-up
              4
              ·
              1 year ago

              Do most editors do that by default? If so, that’s great – if not, it’s just a downside for tabs, if you need to hit enter, backspace out the automatic indents and then press space 30 times rather than just hit enter and have it aligned automatically.

              vim seems to auto-insert tabs when you hit enter mid-function definition, at least with standard settings.

              • wolo@lemmy.blahaj.zone
                link
                fedilink
                English
                arrow-up
                3
                arrow-down
                2
                ·
                1 year ago

                That seems like a problem with Vim, then… Typically I don’t align at all, so I’m not familiar with editor behavior for alignment; I prefer to just indent one level deeper.

          • kevincox
            link
            fedilink
            arrow-up
            4
            arrow-down
            1
            ·
            1 year ago

            Setting tabstop and shiftwidth differently is basically legacy braindead behaviour. It is going back to the logic of tab is just a way to compress spaces. If you are doing that then you have all of the problems of both tabs and spaces.

            As for alignment the easy answer is don’t use tabs for alignment. Use tabs for indentation, if you want to align something use spaces for the alignment past the indentation. Lemmy seems to be breaking code snippets right now but I have a really old blog post about this.

            https://kevincox.ca/2014/06/26/responsive-tabs/

            The post is a little out of date when referencing the style of my blog but the C example shows alignment. If you can resize the browser you can see that the indention changes from 4 to 2 as the screen gets narrower without breaking the alignment.

      • JackbyDev@programming.dev
        link
        fedilink
        English
        arrow-up
        9
        arrow-down
        2
        ·
        edit-2
        1 year ago

        Using only tabs for indentation and only spaces for alignment will never result in crap alignment when adjusting tabstops because the alignment does not use tabs.

        This is using both tabs and spaces for alignment.

        --->func foo(int i,
        --->--->     int j);
        

        Observe what adjusting the tabs does,

        ->func foo(int i,
        ->->     int j);
        

        This uses only spaces for alignment,

        --->func foo(int i,
        --->         int j);
        

        When converted the alignment is maintained because the tabstops aren’t used for alignment, only for indentation.

        ->func foo(int i,
        ->         int j);
        
  • Saganaki@lemmy.one
    link
    fedilink
    arrow-up
    19
    arrow-down
    2
    ·
    1 year ago

    Tabs for indentation/increased scope, spaces for alignment. The best answer.

  • Gerbler
    link
    fedilink
    arrow-up
    22
    arrow-down
    5
    ·
    1 year ago

    Yesterday, I shared some spicy takes. A few were particularly controversial—most notably, that I correct Gif the correct way (with a soft G)

    And I stopped reading there.

  • Kissaki@feddit.de
    link
    fedilink
    English
    arrow-up
    32
    arrow-down
    17
    ·
    1 year ago

    I consider tabs for indentation a failed concept.

    The idea is good, but it evidently failed. Most guidelines and newer Tools recommend or require or use spaces for indent. They have their reasons too.

    The prevalence of spaces makes it hard to make a contrary argument for tabs. By now, I don’t think it’s worth even if it had reasonable advantages.

    Editors/IDEs that parse syntax can adjust space indent too. A mixture for indent and alignment is not obvious for everyone (I always display whitespace in my editors and am deliberate and consistent, but many people and editor defaults won’t be). Some defaults of four or eight space-width tab display is atrociously wasteful and inaccessible.

    Spaces are a good enough baseline. It works well enough. And most importantly it works consistently. That’s why it won in prevalence and use.

    • xep@kbin.social
      link
      fedilink
      arrow-up
      7
      arrow-down
      1
      ·
      1 year ago

      If I could only get everyone who works on the thing I work on to use a whitespace visualizer, it would be enough. We can fight about tabs or spaces after we get rid of all the unnecessary trailing ones.

    • ck_@discuss.tchncs.de
      link
      fedilink
      arrow-up
      7
      arrow-down
      5
      ·
      1 year ago

      It works well enough

      is an argument that works for you because you have somewhat healthy eyesight (not counting common glasses).

      It “won” because the majority of healthy people has no problem marginalizing minorities with disabilities.

      • Kissaki@feddit.de
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        1
        ·
        edit-2
        1 year ago

        Do you have actual experience with it?

        Some time ago I read a comment from someone with impaired eyesight who used an editor that would adjust space indent just fine.

        Accessibility is a thing I always consider.

        • ck_@discuss.tchncs.de
          link
          fedilink
          arrow-up
          8
          arrow-down
          1
          ·
          1 year ago

          Not personally, but I had a co-worker once who had an eye condition that made him extremely short sighted to the point where glasses could not fully correct it. He walked around in public using a stick for safety.

          For his work, this meant he had to apply an extremely large front sizes. Since out code base was space indented, in nested places this would result in almost half his screen being blank on the left side because of the space taken to render blanks.

          Sure, we could have just stood out ground and let him solve his own problems somehow. Instead, we made one change to the editorconfig, ran the formatter for a second, he set his tab width to 1 and the world was marginally better for him in less time than it takes me to tipe this text on my phone.

          • Kissaki@feddit.de
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            1 year ago

            I would have preferred tabs to win for this reason.

            Unfortunately, as you pointed out, “good enough” can be excluding, non-inclusive. Overall it works well enough for enough people / none with impairment stumbled over it yet, did not voice or were not heard.

            the majority of healthy people has no problem marginalizing minorities with disabilities

            I wouldn’t attribute malice like this though. Most people just don’t care or are not mindful and thorough.

  • Duralf@lemmy.world
    link
    fedilink
    arrow-up
    13
    arrow-down
    3
    ·
    1 year ago

    This is a holy war that I will gladly fight again and again! I can’t believe that soft tabs are more popular, especially in python!

        • kevincox
          link
          fedilink
          arrow-up
          2
          arrow-down
          2
          ·
          1 year ago

          Actually I think you can technically mix. They have a “conversion factor”. But don’t, because then the code will look like crap on any other tab size (defeating the point of using tabs in the first place)

          I think it would be better that each line needs to start with the exact same bytes to be considered within the same indent level. But I don’t think that is the decision Guido made.

  • Lucky@programming.dev
    link
    fedilink
    arrow-up
    13
    arrow-down
    3
    ·
    1 year ago

    The argument for having tabs adjust depending on your ide sounds better than it is in practice. Someone formatting code to look nice with width 4 will look horrendous for someone who uses width 8.

    Spaces makes it uniform and captures the exact style the original dev intended

    • CodeMonkey@programming.dev
      link
      fedilink
      arrow-up
      12
      arrow-down
      1
      ·
      1 year ago

      If you have your tab width set on 8, that is on you. You will also set your IDE to insert 8 spaces when you press TAB and I will cry when I have to give you a code review.

      When I indent my code, I am indicating that I am in a nested block. I don’t care if, on your screen, that indent is 2, 3, or 4 characters.

        • kevincox
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          That’s fine, when I view it I will get my preferred tab width. This situation is only anarchist with spaces, with tabs they are just a masochist.

    • ck_@discuss.tchncs.de
      link
      fedilink
      arrow-up
      4
      arrow-down
      4
      ·
      edit-2
      1 year ago

      If the original dev intended to make their code less accessible and their project less inclusive in favor of eye candy, they should rethink their priorities.

  • mckean@programming.dev
    link
    fedilink
    arrow-up
    12
    arrow-down
    2
    ·
    1 year ago

    I think calling one way better than the other is flawed. The reason the title is saying that tabs are objectively better is because they are used in addition to where spaces are used elsewhere. You could make the same argument in favor spaces due to keeping things simpler.

    The argument of having variable indent size for tabs so viewers can decide how big they are is imho legitimate but also not the goal as it’s addressing something that teams generally agree on. There is max characters per line, brace placement, general code style and rules. Yes we can eject the indentation from the rules that are agreed on but once again simplicity over complexity has an equal say.

    In the end it doesn’t matter that much, a good programmer will be able to work in either setting, the Editor will do most of the work anyways.

    With all that said, spaces all the way!

  • asudox@lemmy.world
    link
    fedilink
    arrow-up
    11
    arrow-down
    4
    ·
    1 year ago

    Tabs take less space (space as in space in storage, like free as in freedom) tbh.