DEV Community

Discussion on: Why You Should Always Use Curly Braces For Single Statement Blocks In C#

Collapse
 
mileswatson profile image
Miles Watson

I would argue that not using curly braces is fine, as long as you keep the condition and action on the same (short) line. For example, doing a quick check then returning does not need 4 lines when it should only take 1.

If the condition and action are too long to fit on one line, then curly braces should be used for clarity.

Collapse
 
programmerbyday profile image
Arman @programmerByDay

Thanks,
But I think in 2020 we don’t need to be sensitive about number of lines of the code anymore.
Being future-proof and having low maintenance cost that helps code quality is a little higher in priority.

Collapse
 
mileswatson profile image
Miles Watson

One line statements have less visual clutter, so they can arguably be more maintainable than unnecessarily adding curly brackets everywhere.

Do you really need brackets around “if (x < 0) break;” ?

Thread Thread
 
programmerbyday profile image
Arman @programmerByDay

Yeah, That's right it is less visual cluttering.
But I think the other benefits of having brackets (as I mentioned in the post) outperforms that.
I'm all about building a structure in the code to decrease the chance of future mistakes or bugs.