• ggppjj
          link
          fedilink
          22 years ago

          I use a product that has a homegrown scripting language that enforces two space tabs and will crash with anything else.

          • @[email protected]
            link
            fedilink
            Deutsch
            12 years ago

            My main issue is that they keep changing format all the time and making merge requests unnecessarily difficult. Wanna use two? I hate it but fine. But let’s agree on this and change our formatter all at once.

  • @[email protected]
    link
    fedilink
    8
    edit-2
    2 years ago

    Interesting take. I prefer spaces because each piece of code that I see with tabs has an implicit tabsize you really need to have if you don’t want the code to look ugly - especially if the person has been mixing tabs and spaces - and they usually do. Sometimes unadvertently.

    When you remove all tabs at least everyone is on the same page.

    To the actual problem raised by the article:

    I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code. My brain gets too distracted by the visual noise. Someone who’s visually impaired might bump their font size up really large, and need to scale up or down the amount of space per indent. Someone might just prefer it because…

    I wonder if it could be possible to adjust the “indent number of spaces you see” in code editors. Code editors are able to figure out what are indents and what are not, so in theory it should be possible. Perhaps that would be an idea for a new feature?

    • @[email protected]
      link
      fedilink
      12 years ago

      Yes. That’s what tabs are for. You can choose the width of the tab. It can be small for people with small screens. It can be big for this guy or people with 600 inch ultrawides.

      Tabs are objectively superior because they are exactly what everyone wants at all times, and the git commit history does not get polluted.

    • @[email protected]
      link
      fedilink
      132 years ago

      each piece of code that I see with tabs has an implicit tabsize you really need to have if you don’t want the code to look ugly - especially if the person has been mixing tabs and spaces - and they usually do.

      Well written code doesn’t have an implicit tab size. You should be using a tab to mean “one indent” and if you need to align something an exact number of characters then use spaces.

      This is the downside to tabs, they are easier to use correctly. With spaces if it looks right in your editor it probably looks half decent everywhere else. Tabs have a worse behaviour if they are misused, but if used well then every viewer can view and edit with their preferred indent size.

      I wonder if it could be possible to adjust the “indent number of spaces you see” in code editors.

      You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this when we have a perfectly simple and semantic character for indicating what is an indent and what is an alignment.

      Maybe this could be a useful linter though. That way mistakes are caught but not every editor needs a perfect parser of every language.

      • @[email protected]
        link
        fedilink
        42 years ago

        The thing is - I have probably seen hundreds of projects that use tabs for indentation … and I’ve never seen a single one without tab errors. And that ignoring e.g. the fact that tabs break diffs or who knows how many other things.

        Using spaces doesn’t automatically mean a lack of errors but it’s clearly easy enough that it’s commonly achieved. The most common argument against spaces seems to boil down to “my editor inserts hard tabs and I don’t know how to configure it”.

  • @[email protected]
    link
    fedilink
    132 years 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

    • @[email protected]
      link
      fedilink
      4
      edit-2
      2 years 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.

    • @[email protected]
      link
      fedilink
      122 years 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.

  • @[email protected]
    link
    fedilink
    English
    82 years ago

    Tabs let you define how big you want each indent to be, and spaces do not.

    Spaces can too: Simply use more or less of them, to taste.

    I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code.

    Then use four, or six, or eight, or 20. Hell, most code I’ve seen uses four spaces per indent anyway.

    [Re: braille]

    Surely there’s an editor out there that will automatically display indent spaces as a tab character. Or failing that it seems like it would be rather trivial create a program to convert n spaces to tabs, and vice versa.

    • @[email protected]
      link
      fedilink
      132 years ago

      Spaces do not allow the viewer of code to choose how wide the indents are, this is dictated by the developer.

      Most IDEs allow users to customise how many spaces to display tab indents as. Doing so the other way around may cause issues with languages based on whitespaces such as python.

    • @[email protected]
      link
      fedilink
      72 years ago

      You are missing the point. Lots of code has multiple authors. There is offer no space indention that works for all authors. With tabs each author or reader can use the width that works for them.

      automatically display indent spaces as a tab character

      You can’t really do this reliably. The problem is that spaces may be used in other places for alignment where the width shouldn’t be dynamic. If you do a simple s/ /\t/g you will have funny results where code was aligned carefully using spaces. (The reverse does work though if you want to go from tabs to spaces, because tabs contain more information.)

      You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this for no reason. Sometimes I don’t have a full parser available for every language I want to edit.

  • xigoi
    link
    fedilink
    732 years 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.

    • JackbyDev
      link
      fedilink
      English
      112 years 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/

    • z3bra
      link
      fedilink
      532 years 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 ?

      • xigoi
        link
        fedilink
        62 years ago

        It’s not just “might”. Termux is pretty much the only good choice for programming on Android.

        I think 9 is the best size for indent (matter of preference), do you think I should switch to space

        I think you should switch to an exorcist.

        • z3bra
          link
          fedilink
          32 years ago

          What’s your point ? You can use vim on termux and set the tabsize to whatever you want for example.

          • xigoi
            link
            fedilink
            1
            edit-2
            2 years ago

            Yes, but if you use something like cat, head, less, etc. to view code, or the Python REPL, you’re still going to see the default tab size.

            • z3bra
              link
              fedilink
              22 years ago

              You can set the tabstop with less -x*n*. But ok I see what you mean. I still stand by my point though. If termux doesn’t support setting tabstops and it’s an issue, then it’s a bug in termux, not a reason to level down your formatting standard.

    • @[email protected]
      link
      fedilink
      212 years 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)

      • @[email protected]
        link
        fedilink
        English
        62 years 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.

      • xigoi
        link
        fedilink
        132 years ago

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

        • Termux
        • SourceHut
        • “View page source” in the browser
        • @[email protected]
          link
          fedilink
          15
          edit-2
          2 years 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
            link
            fedilink
            English
            32 years 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.

            • @[email protected]
              link
              fedilink
              42 years 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.

              • @[email protected]
                link
                fedilink
                22 years 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.

              • JackbyDev
                link
                fedilink
                English
                22 years 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.

                • @[email protected]
                  link
                  fedilink
                  52 years 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.

    • @[email protected]
      link
      fedilink
      102 years 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
        link
        fedilink
        42 years ago

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

        • @[email protected]
          link
          fedilink
          12 years 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
            link
            fedilink
            32 years ago

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

              • xigoi
                link
                fedilink
                2
                edit-2
                2 years ago

                Be specific. Which exact part would you abstract away and how?

                • @[email protected]
                  link
                  fedilink
                  3
                  edit-2
                  2 years 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.

  • @[email protected]
    link
    fedilink
    English
    312 years 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
      link
      fedilink
      72 years 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.

    • @[email protected]
      link
      fedilink
      72 years 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.

      • @[email protected]
        link
        fedilink
        English
        5
        edit-2
        2 years 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.

        • @[email protected]
          link
          fedilink
          82 years 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.

          • @[email protected]
            link
            fedilink
            English
            1
            edit-2
            2 years 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.

  • @[email protected]
    link
    fedilink
    82 years ago

    That’s all well and good if everyone uses editors you can configure to a certain standard all the time. Then tabs all the way.

    Unfortunately that’s not reality for everyone.

  • @[email protected]
    link
    fedilink
    132 years 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!

        • @[email protected]
          link
          fedilink
          22 years 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.

  • darq
    link
    fedilink
    272 years 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
      link
      fedilink
      112 years 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.

      • @[email protected]
        link
        fedilink
        82 years 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
          link
          fedilink
          42 years 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.

          • @[email protected]
            link
            fedilink
            English
            62 years 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
              link
              fedilink
              42 years 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.

              • @[email protected]
                link
                fedilink
                English
                32 years 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.

          • @[email protected]
            link
            fedilink
            42 years 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
        link
        fedilink
        English
        10
        edit-2
        2 years 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);
        
  • insomniac_lemon
    link
    fedilink
    3
    edit-2
    2 years ago

    I’m tinkering with a whitespace language and prefer using 1-space rather than 2. I don’t really like the double character for 1 level. Is that weird?

    Tabs are forbidden though I could use tabs with a (1-line) per-file code filter for the compiler to turn 1 tab into 2 spaces, and that might be easier when working with others (though I don’t know how it would be seen, especially needing to change editor tab behavior).

  • @[email protected]
    link
    fedilink
    English
    72 years ago

    laughs in lisp

    Nah, I’ll keep on sticking with spaces or whatever the language’s formatter uses. Ain’t no way am I mixing tabs and spaces, will just stick with spaces.

    • Tempy
      link
      fedilink
      42 years ago

      I used to be a tabs guy, somepoint over time, especially when I realized some of the edge cases I have in formatting only remain consistent when using spaces, I switched.

      • @[email protected]
        link
        fedilink
        22 years ago

        Looks like you missed the point. This is about indentation, not formatting.

        Use tabs to indent your lines, but if you want to align a parameter with the parenthesis on the line above or something like that, you add spaces after the indentation tabs.

        That way if someone wants to they can configure their tab length to 20 spaces and the indentation will remain consistent and the code will remain aligned.

        • @[email protected]
          link
          fedilink
          English
          12 years ago

          My point was that it’s pretty much impossible to indent with tabs in lisp. It’ll be harder to read and scan for everyone else who has a different tab with. How you indent and what you want to indent to is very different compared to a c-style language.

    • @[email protected]
      link
      fedilink
      7
      edit-2
      2 years 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.

  • @[email protected]
    link
    fedilink
    232 years 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.