Jump to content

[SOLVED] Which procedure/code is better ?


abdfahim

Recommended Posts

hi friends, i need a little information. Here I am writing two codes that can be used in same purpose.
[code]$new=$_GET['new'];
if ($new==0){
      //Do something
}else{
      //Do something
}[/code]

an alternative is

[code]$new=$_GET['new'];
//$params= something needed inside functions;
if ($new==0){
      func_1($params);
}else{
      func_2($params);
}
func_1($params){
      //Do something
}
func_2($params){
      //Do something
}[/code]

Now my question is which is better and most importantly faster and why ???
Link to comment
Share on other sites

The first is going to be faster as there is always an overhead with function calls as the params and the return address have to placed on the stack. However we're talking nonoseconds here and you are not going to notice in practice.

As far as I am concerned, then, time to execute is not an issue but rather code readabilty and maintenance (that's what costs the money). If "Do something" is just a few lines of simple code I'd use the first. If we are talking something more complex I'd go with second and use meaningful function names so it's obvious what is happening
[code]
switch ($_GET['action']) {

    case 'New' :
            insert_new_record($params);
            break;
    case 'Edit':
            display_edit_form($params);
            break;
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.