6

Where should starting brackets be positioned if/else and function definition in C? Same line or the next line. Have not seen pure cosmetic bullshit like this.

Comments
  • 0
    Depends on the language as well
  • 1
    In C/CPP I've often seen

    keyword
    {
    ...
    }

    While I've seen

    keyword {
    ...
    }

    In most other languages.
  • 4
    Oh boi, let the war begin.
    🍿🍻
  • 1
    It is not purely cosmetic. It affects readability by a lot.
  • 3
    Same line.
    Fewer empty lines to mentally discard that way.

    Programming involves much more reading than writing, so your focus should be on making it is easy to read as possible. Anything that increases the mental effort required to read the code should be avoided. Poor alignment, extra lines, inconsistent styling, unnecessary complexity, poor line length, unnecessary chaining, too long or short names, etc. If it isn't simple, you're doing it wrong.
  • 0
    Not same line. I hate it when block delimiters which I just scan over are intermixed with actual statements.

    However, if a code base has already Egyptian style brackets, I use that because consistency is more important.
  • 3
    Personally I've used and liked both. I also like to add empty lines in my code to make it more readable, but I add them the same way one defines paragraphs. Related lines group together, within reason.

    I do try to extract longer running, well defined sections into their own function though, reducing the need for spacing.
  • 1
    Whichever the styleguide specifies.
  • 0
    I don't know how React for this🤣
  • 1
    @manikandanm Don't. Just view. ^^
Add Comment