Advertisement
  1. Code
  2. Open Mike
Code

Open Mike: Brackets

Languages:

Allman or K&R? This is Open Mike, a series of discussion posts to throw the cat amongst the pigeons. These posts are all about you -- we want to hear your opinions, ideas, and thoughts. To kick things off, let's talk about brackets.


1: Do you Cuddle?

"Cuddling" braces means writing them like this:

Alternatively, there's Allman style:

This Wikipedia entry lists other common styles. Which do you use?

I like Allman because you can do this:

I can easily turn the conditional check off by simply commenting out the 'if' statement. If I was cuddling braces, I'd have to either write a new brace to replace the 'if', or comment out the corresponding closing brace.


2: Do You Pad Your Parentheses?

Compare all of these:

I've seen all of these, in various combinations. I used to use 'padded parentheses', as it seemed easier to see the arguments and their types, but now I prefer 'tight'. What about you?


3: Do You Nest Parentheses in Conditions?

To me, it feels "correct" to write:

...rather than:

...even though the first takes up a lot more space. The parentheses make it clear where the separation lies. But is that small distinction worth it?

One last thing: thanks to Sergio from www.artua.com for the awesome microphone icon!

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.