27-10-2009, 06:37 AM
IMHO, no, a simple if-statement without an else-clause need not be accompanied by a comment indicating the lack of an else-clause. Also, no empty else-clause shall be required. Especially when simple if-statements are encountered, such comments would clutter the code and impair understandability.
E.g.:
If the comment indicates _why_the else-clause is unneeded, that maybe helpful, but should be left to the developer or the code review.
Rule 14.10 explicitly refers to chained if ... else if ... else if ... statements, where for better clarity the braces around the subsequent if-statements are omitted. To compensate for the missing braces (and extra indentation), the final else-clause shall be provided.
Regards,
Johan
E.g.:
Code:
if (a == 1)
{
call_come_function();
}
/* No else needed */
Rule 14.10 explicitly refers to chained if ... else if ... else if ... statements, where for better clarity the braces around the subsequent if-statements are omitted. To compensate for the missing braces (and extra indentation), the final else-clause shall be provided.
Regards,
Johan