3 ms·
This doesn't actually save anytime or space, and just adds a confusing layer. If you have to explicitly define a map of the name of the argument to the value o
by wdewind 14y ago
This doesn't actually save anytime or space, and just adds a confusing layer. If you have to explicitly define a map of the name of the argument to the value of it, it's not significantly shorter than just assigning the value to the name of a variable and passing that in, ie:
$some_user_flag = true;
$some_other_flag = false;
$user->someFunction($some_user_flag, $some_other_flag);
vs. (assuming $user->someFunction is now your already defined/returned function because this has been abstracted away in your stack somehow):
$user->someFunction(array(
'some_user_flag' => true,
'some_other_flag' => false)
);
- iamumassthrower 14y agoIt's not about brevity. Do you like extending functions that are called in 1500 places by adding another un-named parameter? Unless the function you're writing is something that intrinsically should always take the same parameters that it starts with, named parameters are better. If I'm implementing function add_one($number){ return $number++; } then there's no need for named parameters. If I'm implementing function send_email($args){...} then I'm going to go with named parameters.