Home > Uncategorized > Indent/Bracketing Style

Indent/Bracketing Style

It seems one of the guaranteed ways of starting a war between geeks is to push one style of bracketing over another. The main battle is typically between Allman and KNF. See Indent Style on Wikipedia for more background.

Allman style says:

if (a == b)
  do something;
  do something else;

KNF says:

if (a == b) {
  do something;
} else {
  do something else;

Each camp has their own arguments for which one is perfect and I dare say this argument will rage on forever, along with tabs vs spaces and leaving spaces around operators, operands and parameters.

Personally, I’m a fan of KNF for the simple reason it’s more compact vertically – why do something in 8 lines when you can do it in 5. I achieve the same clarity, i.e. ability to match opening and closing braces but don’t scroll through lines with a single character on them. Even with a large monitor I still don’t want to waste it. After all, I did pay for every pixel.

However, I think whatever style you prefer, you should stick to it and adopt coding standards that other team players stick to. If not, you better make use of the online code prettifiers, or maybe write a script that can validate everything, i.e. class names, variable names, space around operators, indent style, etc.

Categories: Uncategorized Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: