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

    good. article upvoted. as are also good curly braces after if/else. too many times I’ve seen if/else without curly braces. why I should carefully read tens of loc, to find ifs? why can’t I find it at a glance, quickly scrolling the file? y do i have to read the line horizontally too to understand if the instruction is there or in the following line? why do I HAVE to add the curly braces to fix stuff? juniors get arty with this “feature” and unwrapping their logic becomes a real pain: but it looks so good!

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

      I agree with the need, but not your rationale, I’m in the “always curly braces” camp for two reasons:

      • when a second line gets added in a condition block, the braces might not get added, a bug.
      • one less decision to make while coding. Anything that removes trivial decision-making can speed up authoring and reading code.
      • rodolfo@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        well, in my rant, the bit about why do I have to add braces to fix stuff is very close to your first point, and the bit about reading while quickly scrolling to your second point, in which you say the right thing: not adding braces is something that one actively does. with no acceptable reason ever, imo.

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

          Well, a couple things:

          My points are related to provable advantages to doing it while writing code. They’re also not argumentative.

          Your points are related to a personal preference of aesthetic while reading code. They are not provable advantages. They’re also quite “ranty,” which is rarely a persuasive way to convince someone of your position.

          If you actually want to get people to change their habits around this, I think you’ll have better luck with my approach than ranting about why you don’t like how it looks.

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

            if aesthetics reason is what gets through, I’m really lost then. for sure that’s a rant. thank you, have a nice day