Saturday, 8 October 2016

Pet Peeve: Statements not wrapped in braces

Jumping into a new code base I've had time to stew on some of my pet peeves when it comes to coding style. Maybe this is just me being a pedant, but statement that aren't wrapped in braces really grind my gears. I find this particularly prevalent with one line if statements, but it pops up with other cases (while, for, using in C#, etc) from time to time.

The reason that this works at me particularly is that these statements have removed one of the visual cues native to the language and sit outside of the typical visual flow of the code. I rely on the flow and visual cues to quickly parse the flow of a piece of code.

In the worst case the removal of this visual cue increases the likely hood of making a simple mistake because the operation of the program can be accidentally changed, for instance adding a log line directly below the if statement will cause what was previously in the statement to be run consistently.

Rant Over.

P.S.  I'm hardly going to shout you down for using statements without braces. I just don't like them is all.