Validation - coding standard

Discussion in 'iOS Programming' started by MacMan988, Apr 7, 2014.

  1. MacMan988 macrumors 6502a

    Joined:
    Jul 7, 2012
    #1
    Hi, I've been writing validation related "if conditions" in two different ways and I wonder what would be the better way to do. I want to improve my code quality.

    first method:

    Code:
    -(void) someMethod {
    
        ...
    
        if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) {
        
            //  send email    
    
            ...
        
        }   else  {
    
            // show error
    
            ...
    
        }
    
    }
    second method:

    Code:
    -(void) someMethod {
    
        ...
    
        if ( ![[NSFileManager defaultManager] fileExistsAtPath:path] ) {
        
            //  show error
      
            ...
    
           return;
         
        }
    
        // send mail
    
        ...
    
    }
    If non of these methods are correct, please tell me the best way to write it. Thanks.
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    I would tend to structure the code more like the second layout. Just because it leads to less indentation and makes the 'success' path flow a little better. It's all personal preference. Note that when it comes to execution performance, it doesn't matter which of those you choose.
     
  3. MacMan988 thread starter macrumors 6502a

    Joined:
    Jul 7, 2012

Share This Page