说明:The goal here is to make the code on the left margin to be the “expected”
code execution path and the code that is indented to be the exception. Consistency
in this area is important to code readability.示例:
良好的风格:
-(void)someMethod{
if (![someOther boolValue]) return;
//Do something important }
不良好的风格:
-(void)someMethod{
if ([someOther boolValue]) { //Do something important}}
================================
良好的风格:
-(void)someMethod{if ([someOther boolValue]) { //Do something important return;
}
//Do something else important }
不良好的风格:
-(void)someMethod{
if ([someOther boolValue]) { //Do something important
} else {//Do something else important
}}
================================
例外:
-(void)someMethod
{if ([someOther boolValue]) {
//Do something important } else {
//Do something else important }
//Do this no matter what }
网友评论