Tuesday, September 11, 2012

Worse Development Anti-Pattern I've Ever Seen: Using Goto in Objective-C

This is actual code I was reviewing a few months ago. I've anonymized the code and did a bit of renaming... 
- (BOOL)aTerribleMethod:(NSString *)iDontKnowWhatImDoing
{
    if(iDontKnowWhatImDoing isEqualToString:@"YES") {
        [self callAnotherTerribleMethod];
        goto bail;
    }

    if(iDontKnowWhatImDoing isEqualToString:@"SOMETIMES") {
        [self callYetAnotherTerribleMethod];
        goto bail;
    }

    if(iDontKnowWhatImDoing isEqualToString:@"NO") {
        goto bail;
    }

    //Do a whole bunch of other stuff

    bail:
}
If you've ever written something like this, please quit programming.