Live data from Hacker News

Named arguments are coming in PHP 8

stitcher.io

51–60 of 140 posts

Re: Named arguments are coming in PHP 8

#51
post #8

I'm ambivalent. There's a tension in PHP-land between PHP's roots as a low-ish level, get-it-done, hackish language, with its big standard library and simple scalar types, and the better-organized and quite vocal developers who want it to be more Java-like, with great big frameworks and many deeply-nested complex class hierarchies. Instead of unwieldy hobbyist-hacker balls of mud, you build enterprise-scale balls of…

> 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.

Re: Named arguments are coming in PHP 8

#52

Named arguments is a no-brainer for me for any kind of programming language. I am hoping D adopts named arguments too, although it's a very uphill battle there with many programmers coming from C/C++ background being opposed to it in the name of API stability.

I agree, it is a sensible improvement. What I don't like is spread operators in every form, but I can certainly live without

  funcy(null, null, null, null, null, null, cake, null, lie)...

Re: Named arguments are coming in PHP 8

#54
Two of the languages I use most often (Python and Raku (formerly known as Perl 6)) have named arguments, and it improves clarity of code tremendously.

I don't know how well it fits into PHP, but if it's anything like in python or raku, go for it! :-)

Re: Named arguments are coming in PHP 8

#56

I'm ambivalent. There's a tension in PHP-land between PHP's roots as a low-ish level, get-it-done, hackish language, with its big standard library and simple scalar types, and the better-organized and quite vocal developers who want it to be more Java-like, with great big frameworks and many deeply-nested complex class hierarchies. Instead of unwieldy hobbyist-hacker balls of mud, you build enterprise-scale balls of…

[deleted]

Re: Named arguments are coming in PHP 8

#57
post #19

Earlier quoted context omitted.

> and basically nobody does that anyway. That's it, I'm officially a nobody :-)

> leaves it up to the called function to sanity-check the input types instead of letting the compiler do it, and basically nobody does that anyway. You don’t check the input types?

Not in get-it-done, hackish scripts.

Re: Named arguments are coming in PHP 8

#58
There was a time when I would've been all-out in favor for this because one of the most often used functions in Drupal had no less than seven arguments: https://api.drupal.org/api/drupal/includes%21common.inc/func... it being seven, the running joke was knowing the Seven Parameters Of L is our initiation rite.

Then the options collapsed into an array https://api.drupal.org/api/drupal/includes%21common.inc/func... and that was in 2008.

And then URLs in 2015 became a value object and while you can still pass absolute => TRUE in options if you really want to, you can just call setAbsolute() on the object.

I guess if PHP core adopts this , phpstorm will quickly adopt as well and typing strpos( will immediately expand to strpos(haystack: , needle: so you can just fill that in. I guess? so maybe a reluctant yes but I am a bit wary of the APIs that will follow from this. I guess I have slowly grown fond of value objects? I must be getting old.

Post reply on HN