Raised This Month: $ Target: $400
 0% 

Code Style


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-16-2010 , 12:21   Re: Code Style
Reply With Quote #4

Firippu you are wrong about method 2 being better.
It makes no difference in efficiency, but you can use it to make your code easier to read.

Instead of this:
PHP Code:
public function(){
    if(
condition1){
        
//code1
        
if(condition2){
            
//code2
            
if(condition3){
                
//code3
                
if(condition4){
                    
//code4
                    
if(condition5){
                        
//code5
                        
if(condition6){
                            
//code6
                            
if(condition7){
                                
//code7
                            
}
                        }
                    }
                }
            }
        }
    }

It can look like this:
PHP Code:
public function(){
    if(!
condition1)
        return
    
//code1
    
if(!condition2)
        return
    
//code2
    
if(!condition3)
        return
    
//code3
    
if(!condition4)
        return
    
//code4
    
if(!condition5)
        return
    
//code5
    
if(!condition6)
        return
    
//code6
    
if(!condition7)
        return
    
//code7

__________________
Impossible is Nothing
Sylwester is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode