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

  • z3bra@lemmy.sdf.org
    link
    fedilink
    arrow-up
    1
    ·
    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
      0
      arrow-down
      1
      ·
      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
        0
        ·
        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
          0
          ·
          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.

          • z3bra@lemmy.sdf.org
            link
            fedilink
            arrow-up
            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)
            
  • stevecrox@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    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.

  • xigoi@lemmy.sdf.org
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    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
      3
      ·
      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@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      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
        1
        arrow-down
        1
        ·
        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
          1
          ·
          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.

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

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

  • darq@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    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.

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

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

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

  • potterman28wxcv@beehaw.org
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    edit-2
    1 year 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?