This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Excessive use of parenthesis

When writing C, we've all heard people say "it doesn't hurt to use extra parenthesis" or "if in doubt, enclose it in parenthesis".

Now, while both of these statements are basically correct in their applicable context, I personally feel that excessive use of parenthesis (especially where they're not needed) is indicative of an author who is uncertain of operator precedence, and frankly it drives me nuts.

Personally, I place more importance on understanding and knowing operator precedence (even if it means keeping a little cheat-sheet pinned on your office wall) than on "feeling secure" by flooding/obscuring the code with just-in-case parenthesis.

Am I being fussy?

Parents
  • Personally, I warmly encourage the use of a few "blind and very stupid rules", the more "stupid" the better, including the use of "unnecessary" parenthesis and white spaces between operators, because of the following reasons:
    - not all the programmers in a team may have the same skill, so maybe not everyone always remembers the correct precedence rules, and no cheat leaflet will help you, if you just don't read it...
    - the produced code may be "more readable with less effort"
    - you never know what you can do at 2 o'clock in the morning, when you are late in a project and deeply under pressure: if you develop rules that allow you to write your code in a very "stupid and automatic" mode, you can "fire and forget" parenthesis, operator precedence and so on, to keep your last awake brain neurons focused on what you really are doing; in my case, this will help me to defend myself (and my code) from my own stupidity.

Reply
  • Personally, I warmly encourage the use of a few "blind and very stupid rules", the more "stupid" the better, including the use of "unnecessary" parenthesis and white spaces between operators, because of the following reasons:
    - not all the programmers in a team may have the same skill, so maybe not everyone always remembers the correct precedence rules, and no cheat leaflet will help you, if you just don't read it...
    - the produced code may be "more readable with less effort"
    - you never know what you can do at 2 o'clock in the morning, when you are late in a project and deeply under pressure: if you develop rules that allow you to write your code in a very "stupid and automatic" mode, you can "fire and forget" parenthesis, operator precedence and so on, to keep your last awake brain neurons focused on what you really are doing; in my case, this will help me to defend myself (and my code) from my own stupidity.

Children