Some useless coding standards

I have found that some people (individuals or organizations) adopt some coding standards that are quite useless if not harmful. Here they are:

* Exit functions only at their end. This rule was be good in the old days when there weren’t exceptions. Now, having the possibility to exit prematurely a function when an exception is raised, it is pointless to force the control flow to reach the end of every function. Intermediate “return”s are quite handy, and they are safe, given that resources are propery released by garbage collection, or “using” clauses, or RAII (in C++).

* Always end “default” case of switch with a “break” statement. As “default” is always the last clause, there is nothing to break.

* Never split on several lines a function call or a function declaration (known in C language as “function prototype”). Some function calls and some function declarations are quite long; if you do not split them, you end up with an unwieldly long line. On the contrary, it may be advisable to dedicate a line for every parameter in a function declaration, to add inline comments.

* When splitting a statement, start the next line just under the last open parenthesis of the previous line. If that open parenthesis is at the end on the line, you are forced to start the new line at the right end of your screen. Instead I suggest to indent always by the same amount of chars (I use 4 chars).

* Add parentheses whenever you have a doubt about the precedence of operators. As every programmer has his/her doubts, this is not a standard. Precedence of operators are meant to avoid parentheses. If you have doubts, study better the language, or use another language, or simplify the statement.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s