ustwo / objective-c-style-guide

The ustwo Objective-C style guide
20 stars 5 forks source link

Switches Have Brackets #9

Open martinstolz opened 10 years ago

martinstolz commented 10 years ago

Switches also must have brackets. Why? Consistency and visual separation of code blocks.

switch (value)
{
    case 0:
    {
        [self doSomething];
        break;
    }
    case 1:
    {
        [self doSomethingElse];
        break;
    }
}

:+1: or :-1: ?

KATT commented 10 years ago

I'm :thumbsdown: to switches in general.

martinstolz commented 10 years ago

@KATT me too. But if used?

KATT commented 10 years ago

Maybe have guideline of not using switch instead?

alexfish commented 10 years ago

what have you got against switches? :frowning:

martinstolz commented 10 years ago

As Apple shows, it is more prone to errors and you can only "switch" integers. I still use them but probably not for less than two or three cases.

alexfish commented 10 years ago

switches :heart: enums

alexfish commented 10 years ago

Can we add this section? We should also mention that the break should be inside the brackets for readability