views:

134

answers:

6

Possible Duplicate:
Is there a best coding style for indentations (same line, next line)?

I noticed in Objective C that xcode automatically uses a strange position of braces:

if (statement) {
}

whereas I am used to using:

if (statement)
{
}

it just makes it easier to read. Is it a matter of preference or is a standard that should be followed when writing Objective C applications?

A: 

I would assume that like c++ objective C ignores white space. Both are valid, it's just a matter of taste.

Holman716
A: 

Like you said, it just makes it easier to read. There's nothing more to it, so don't worry; if you have your own style or standard of placing braces, there's nothing wrong with following it!

BoltClock
+5  A: 

It doesn't matter.

Apple won't read your code and reject that because of wrong indentation style[1].

If you're unhappy with the brace position, you could change the XCCodeSenseFormattingOptions. You probably need

    XCCodeSenseFormattingOptions = {
       BlockSeparator = "\n";
    };

Note: [1] I do not guarantee if they will expand section 3.3.1 to enforce the indentation style.

KennyTM
I'd love to see them ban Hungarian notation, please!
BoltClock
+1 for making me laugh so hard!
Jason Coco
A: 

It is a definitely a matter of preference. I think you can configure xcode to use your preferred bracket placing.

Kungi
A: 

Preference, just like most (all?) other languages that use braces.

I tend to put mine at the end of the line - that's how I was originally shown, and that's how I prefer. I feel the code looks cleaner that way, plus the } is (should be) the next thing at the same indent level.

but that's my opinion, and everyone else has one, too.

Wayne Werner
Yes, I have an opinion and it's different to yours. I find the code looks less clean with the brace at the end of the line and having the two braces at the same indent level bracketing the block helps to delineate it better. The other way in which my opinion is different to yours is in that I am right :-) or not.
JeremyP
I actually find it kind of interesting - when I'm coding by myself in vim/emacs, I always put the { at the end of the line, but if I'm coding in Eclipse et al, I tend to ignore the braces completely because they're taken care of by Eclipse. Also when you take into account that { } are just scope operators and at least in C/++ they can appear anywhere, it becomes another question of style - do you write your statements after a conditional or on the line below a conditional? <ominous music> dun dun daaaah...
Wayne Werner
A: 

The choice of brace position is not as important as being consistent with the one you choose (IMO). Also when dealing with questions like these it helps to remember that objective-C is a superset of C, so if it worked in C it should work in objective-C.

Nebs