• rodolfo@lemmy.world
    link
    fedilink
    arrow-up
    1
    arrow-down
    6
    ·
    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
      1
      ·
      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.