Why wouldn’t you use brackets?

Brackets and Braces

I wonder why some programmers are so averse to using curly braces and brackets in all situations to explicitly state intended behavior. Without explicit curly braces, you can run into the following scenarios. Here are two examples which didn’t pop up right away during a quick code review but were found later and could have caused some havoc.

For Scenario #1, aside from the fact that the conditional operator is not needed, the problem was the priority of the conditional operator compared to that of the bit-AND operator. It might not stand out immediately depending on the spacing because you might read the operators priority differently.Scenario #2 has the problem of secretly hiding the second if condition under the else. Whether or not it is the intended functionality, it’s just plain confusing.

I like the idea of -Wparentheses being turned on…

Quick Aside

Has anyone had any experience using Lint or adding it to a large existing project? I remember having used it at a previous co-op and although a lot of the code had to include pre-processor directives in order to tell Lint that these are not actual errors, I thought the overall quality of the software improved due to it’s use.

Leave a Reply

Your email address will not be published. Required fields are marked *