1.33、建议:做条件判断时,应使用Golden Path模式

说明: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 }

你可能感兴趣的:(1.33、建议:做条件判断时,应使用Golden Path模式)