Welcome Guest, Not a member yet? Register   Sign In
Best practice to maintain your code readability, etc.
#10

(This post was last modified: 07-14-2018, 10:19 PM by John_Betong.)

(07-10-2018, 11:24 PM)Pertti Wrote: >>> Another neat way to simplify code is to drop nested if-else statements and exit method as early as possible.

As mentioned I prefer declaring a default  $result and only returning a single $result.

Each to their own [Image: smile.gif]
PHP Code:
//===================================
function test_2($input)
:
int
{
  $result = -9999999// DEFAULT

  if (! is_integer($input))
  {
     // DEFAULT // false;
     // $result = -9999999; 

  }else if ($input 0) {
    $result $input 3;

  }else if ($input 100) {
    $result $input 2;

  }else if ($input 50) {
    $result =  $input;

  }else {
    $result =  $input 4;
  }

  return $result;
}
  
Reply


Messages In This Thread
RE: Best practice to maintain your code readability, etc. - by John_Betong - 07-14-2018, 10:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB