Avoid duplicating the code
hi guys..im interested in 'small' improvement in coding, lets say i have:
Code:
if( get_pcvar_num( cvar1 ) ) Code:
if( get_pcvar_num( cvar1 ) ) |
Re: Avoid duplicating the code
Instead of checking if the criteria is true and doing the code there, check if it's false and do "return". Then the code will continue naturally to the 20 lines you need after both checks.
|
Re: Avoid duplicating the code
If i undestand you correctly, you are aiming to the 'TEST'...Maybe i gave bad example with it, i have some 'comlpex' IF on both situtaions, so TEST < 0 and TEST > 1 was just a confusing ...see updated post
ps: i saw somewhere, there is option to add 'do:' but cant find it anymore, mby it will do the trick |
Re: Avoid duplicating the code
Code:
|
Re: Avoid duplicating the code
Or
Code:
|
Re: Avoid duplicating the code
CrazY's post is what I meant. I was too lazy to write down the example from my phone.
hleV - alternatively, he can use "goto" because the code is located in the same function, but the best way IMO is eliminating all the false checks and stopping the function. |
Re: Avoid duplicating the code
PHP Code:
Also you can use other ways depending on the variables scoop value and the cvar If you fully duplicating the code means there is no different in body of the code of blabalabla and tuctuctuc why just do it in a one sentence PHP Code:
|
Re: Avoid duplicating the code
Thanks guys...i used
Code:
public func1() 'go to:' or 'do:' came to my mind, but it seems more complicated to be added |
All times are GMT -4. The time now is 12:26. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.