c# - Single statement conditionals - why is the pattern not used for other code blocks? -


just thought i'd see if explain why anders decided valid...

if(...)    //single statement else    ///single statement 

but not...

try    //single statement catch    //single statement 

to quote framework design guidelines in section "general style conventions" said braces:

avoid omitting braces, if language allows it. braces should not considered optional. single statement blocks, should use braces. increase code readability , maintainability.

there limited cases when omitting braces might acceptable, such when adding new statement after existing singöe-line statement either impossible or extremely rare. example, meaningless add statement after throw statement:

if(someexpression) throw new argumentoutofrangeexcetion(...);

another exception rule braces in case statements. these braces can omitted caseand breakstatements indicate begining , start of block.

what anders thinks subjective , argumentative, recommendation.

you might want @ section bracing in coding convention on @ msdn.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -