https://github.com/nurettin/pwned/blob/770144a15efe7ab96bf4d...
Named arguments are coming in PHP 8
61–70 of 140 posts
Re: Named arguments are coming in PHP 8
#62Not sure if the standard library has evolved since my PHP days, but this would at least solve the "key / haystack" issue. In which lots of the standard library had different orders in which parameters are passed. One can finally pass them named and no longer have to care about the order. This may also have been solved by better tooling since then, though.
Re: Named arguments are coming in PHP 8
#63There are a lot of arguments surrounding this subject. Just came in here to chime about how I miss named arguments in c++. Sure, I can emulate them [0] but at the cost of ide support, runtime and compile time. https://github.com/nurettin/pwned/blob/770144a15efe7ab96bf4d...
Re: Named arguments are coming in PHP 8
#64Do people naturally try and reinvent that feature in its absence?
So for named parameters you have:
1. Javascript would often be written with methods with a single "options" parameter, where "options" is an anonymous object and basically a map;
2. Day-to-day I write Hack. Many functions are similarly written taking a shape as an argument. Shapes are structs, basically, but the typechecker is smart enough to treat them as a well-defined by anonymous type.
3. I've also seen C code that does much the same with things structs.
Empirically there seems to generally be a demand for this kind of feature and it makes sense: long parameter lists are tedious and error-prone (have you ever seen a function that has 3 boolean parameters in a row?) where people try and be helpful by providing "optional" parameters (which are really just parameters with default values).
So sure, I'm all for named parameters.
Re: Named arguments are coming in PHP 8
#65There are a lot of arguments surrounding this subject. Just came in here to chime about how I miss named arguments in c++. Sure, I can emulate them [0] but at the cost of ide support, runtime and compile time. https://github.com/nurettin/pwned/blob/770144a15efe7ab96bf4d...
They are effectively in C++20 without real penalty (designated initializers).
Re: Named arguments are coming in PHP 8
#66Not sure if the standard library has evolved since my PHP days, but this would at least solve the "key / haystack" issue. In which lots of the standard library had different orders in which parameters are passed. One can finally pass them named and no longer have to care about the order. This may also have been solved by better tooling since then, though.
a proper IDE solves that, but i always laugh when getting back to php why they made array_map and array_filter switch parameter order.
It kind of makes sense if you look at the signatures (array_map takes a callable and a variable number of arrays, while array_filter takes a singe array and an optional calable), but yeah, it's horrible to use.
Re: Named arguments are coming in PHP 8
#67It's beginning to look a lot like -- typescript
generally yes, but specifically here typescript does not have named parameters (yeah you can emulate with a hack through object literals which is sad)
Re: Named arguments are coming in PHP 8
#68I really love this new feature however my only concern is that renaming some parameters will trigger a lot of changes in other places as a side effect, thus polluting diffs.
Now, I admit cluttered diffs can be a problem, but there are workarounds: more fine-grained commits (especially separate commits for renames only) and better diff display. As an example of the latter: another commnter mentions one argument per line produces better diffs. It does for your standard display with +++/---, but tools like Sublime Merge have this covered and siplay the change in such a way you can immediately see what argument changed it's name, inline in the code. If it's was just a typo fix it will usually only highlight the changed character(s) not the complete name. Even going from all arguments on one line to one agrgument per line is covered, since it'll just display it as added whitespace and won't highlight the argument themselves indiacting they did not change.
Re: Named arguments are coming in PHP 8
#69Re: Named arguments are coming in PHP 8
#70Earlier quoted context omitted.
> break the function signature into one-line-per-parameter, which is vile Speak for yourself. If each line indicates what it is the parameter for I couldn’t care less. Nobody will use this for functions that have just two parameters. It’s the ones that have 10 possibilities that are crazy.
Other than plain object constructs these kinds of functions are unheard of and better handled with a parameter object or array. I can't help but feel if they just set up a clean way to name construct Params for classes this wouldn't need to happen.
What is the functional difference between a named construct "Params" and just allowing named parameters?