• @lightsecond@programming.dev
      link
      fedilink
      9
      edit-2
      10 months ago

      If you’re using monospaced fonts for writing code (please tell me you are) spaces make sure that the code will look roughly the same on everyone’s machine.

      def function(paramX: str,
                   paramY: str,
                   paramZ: str) -> int:
        pass
      

      If I’d used tabs, the second and third parameter might not align with the first.

      Also, left-side indentation is only a small part of the overall whitespace in code. You’re adding whitespace even when you write x = y. Spaces make sure that this whitespace around the = grows in the same scale as the indentation.

      • @aidan@lemmy.world
        link
        fedilink
        610 months ago

        Yes but it’s not your job to make sure your code looks the same for everyone else. If they’d prefer to read it with a different tab size, maybe they’re using a smaller screen, or a larger one because of vision issues there’s no reason they shouldn’t. You can use an optional editor config if you want it to be able to look the same for others.

        • @lightsecond@programming.dev
          link
          fedilink
          410 months ago

          It makes a difference when you’re working on a large project with lots of people. Even Linux mandates 1 tab = 8 spaces.

          The only argument i see in favour of tabs is the “i can change the width on my own machine!” which isn’t very convincing if you are working on a team and need to follow conventions every time you commit code. The indentation will keep looking weird on your machine.

          • @aidan@lemmy.world
            link
            fedilink
            310 months ago

            Yes so you can choose to follow that convention, but it being adjustable for reading is very useful for reading on different screensizes or with eyesight issues. Why not just set what you want in an editor config?

            • @lightsecond@programming.dev
              link
              fedilink
              310 months ago

              Well, life is about trade-offs and neither spaces or tabs are perfect in every scenario, but the industry overall prefers spaces over tabs nowadays and the tooling reflects that too. For me personally, as long as a project is consistent in its formatting and developers don’t need to fight its tooling, I’m happy with either. We can yak shave all we want (and lots of people are doing that on the internets) but I hope I at least answered your initial question about why people prefer spaces over tabs.

    • BrerChicken
      link
      fedilink
      310 months ago

      I will never understand why people are so set on spaces…

      They just never really understood tabs. If they did, they wouldn’t be sitting there counting how many times they hit the space bar!

        • Adda
          link
          fedilink
          13 years ago

          Yeah, my favourite write-up about this topic is this one. Sadly, it has become normal to use spaces everywhere.

          • @carbon_dated@lemmy.ml
            link
            fedilink
            1
            edit-2
            3 years ago

            Seems like a good idea, but one thing that worries me is that unless I configure my editor to highlight tabs or to mark them or use a linter, it can be pretty hard to tell if you have been consistent in your use of whitespace (because it can be difficult to distinguish them). Another problem is that for example my code would look awful, if it used tabs instead of spaces for indentation, in editors like notepad that can’t set the tab width (each indent is originally supposed to be 2 spaces wide, because GNU Coding Standards).

            How do most autoindent editors react by default when mixing tabs with spaces? If they break, that would be another problem, because that would mean that contributors would have to create an editor config just to be able to remain consistent with my project’s style guide.

            • Adda
              link
              fedilink
              13 years ago

              I must agree with both your points. At least to my knowledge, there are no problems with editors when using both tabs and spaces, but I have not used tabs in a while, so I cannot be sure about it. I still like the idea, but do not use it myself very often (ever) and definitely never when working in a team or working on something that could be viewed and/or edited by others for sure.

  • @adrianmalacoda@lemmy.ml
    link
    fedilink
    3
    edit-2
    3 years ago

    Hot take: Tabs are the objectively correct way to do indentation. The main argument I have seen in favor of spaces is that they give you finer control over how the code looks, but semantically, one tab is one level of indentation, and the exact appearance of a tab is best left to editor preference. Nonetheless, I use spaces because everyone else uses spaces, and I would rather be consistent with existing code bases than bikeshed over ultimately unimportant concerns. I suspect this is the reason why spaces became so popular in the first place.

    • @sacredbirdman@lemmy.ml
      link
      fedilink
      03 years ago

      So, what’s the semantic indentation level for say function arguments when the first is after the function and the others are on new lines aligned with the first? Why not leave indenting to the editor?