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
case
andbreak
statements indicate begining , start of block.
what anders thinks subjective , argumentative, recommendation.
you might want @ section bracing in coding convention on @ msdn.
Comments
Post a Comment