Is brackets better or no brackets for single-line blocks?

What is the best coding practice for single-line code blocks after an if statement - parentheses or curly braces? Just to avoid too much "Well, it depends on what language you use ...", say for C #. In other words, which is better:

if(somecondition) { singleLineStatement; } 

or

 if(somecondition) singleLineStatement; 
+4
source share
1 answer

I think consensus is using braces. If you omit curly braces, there is a risk that someone will add an extra line without noticing missing curly braces.

+7
source

All Articles