• eee@lemm.ee
    link
    fedilink
    arrow-up
    18
    ·
    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

  • Lucky@programming.dev
    link
    fedilink
    arrow-up
    13
    ·
    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
      ·
      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@lemmy.ml
          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
      ·
      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.

  • xigoi@lemmy.sdf.org
    link
    fedilink
    arrow-up
    8
    ·
    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
      6
      ·
      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 ?

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      5
      ·
      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/

    • IRQBreaker@startrek.website
      link
      fedilink
      arrow-up
      5
      ·
      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
        3
        ·
        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
          0
          ·
          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
            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.

    • kevincox@lemmy.ml
      link
      fedilink
      arrow-up
      4
      ·
      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
        3
        ·
        1 year ago

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

        • Termux
        • SourceHut
        • “View page source” in the browser
        • kevincox@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          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
            0
            ·
            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@lemmy.ml
              link
              fedilink
              arrow-up
              1
              ·
              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
                0
                ·
                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@lemmy.ml
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  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.

      • Faresh@lemmy.ml
        link
        fedilink
        English
        arrow-up
        0
        ·
        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.

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

  • stevecrox@kbin.social
    link
    fedilink
    arrow-up
    4
    ·
    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
      0
      ·
      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
        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.

  • mckean@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    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!

  • zygo_histo_morpheus@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    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
      1
      ·
      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
        1
        ·
        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.

    • ck_@discuss.tchncs.de
      link
      fedilink
      arrow-up
      0
      ·
      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.

  • Kissaki@feddit.de
    link
    fedilink
    English
    arrow-up
    1
    ·
    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
      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
      0
      ·
      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.

  • vzq@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    1
    ·
    1 year 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.

  • SleveMcDichael@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year 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.

    • kevincox@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      1 year 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.

    • spiderplant@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      1 year 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.

  • skulbuny@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year 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@lemmy.temporus.me
      link
      fedilink
      arrow-up
      1
      ·
      1 year 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.

      • Phen@lemmy.eco.br
        link
        fedilink
        arrow-up
        0
        ·
        1 year 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.

        • skulbuny@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year 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.