Live data from Hacker News

Named arguments are coming in PHP 8

stitcher.io

81–90 of 140 posts

Re: Named arguments are coming in PHP 8

#81
> named arguments allow you to pass input data into a function, based on their argument name instead of the argument order

Granted, I'm not a PHP developer, but I can't understand why a change like this would be controversial. It sounds like it's optional, and would help greatly to reduce mistakes when passing arguments to functions? Having multiple lines of things being passed to a function may look odd to some, but couldn't the same argument be made as with arrays, that one line per "thing" makes sense, if nothing else to clean up diffs when collaborating on code?

Re: Named arguments are coming in PHP 8

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

> Nobody will use this for functions that have just two parameters. It’s the ones that have 10 possibilities that are crazy.

It can be super useful even for functions with low arity e.g. `max(seq, key=func)`.

Re: Named arguments are coming in PHP 8

#84
post #40

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…

> There's a tension in PHP-land between [...] hobbyist-hacker [vs] enterprise-scale IMO the same tension exists in Python. The hobbyist-hackers are using the language to write small-ish scripts, and the enterprise-scale developers are working on million-line codebases. Unfortunately for the hobbyist-hackers, at some point (perhaps when the BDFL started working at Dropbox), the focus of the language shifted from the f…

> Python now has a complex type system - that many developers never use.

Python doesn't have a complex type system. How could it when, to this day, it doesn't bundle a type-checker?

Python had a way to annotate functions (PEP 3107), which the community largely used for type-hinting, so Python introduced better support for type hints (PEP 484 and various extensions since).

Re: Named arguments are coming in PHP 8

#86
post #40

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…

> There's a tension in PHP-land between [...] hobbyist-hacker [vs] enterprise-scale IMO the same tension exists in Python. The hobbyist-hackers are using the language to write small-ish scripts, and the enterprise-scale developers are working on million-line codebases. Unfortunately for the hobbyist-hackers, at some point (perhaps when the BDFL started working at Dropbox), the focus of the language shifted from the f…

> IMO the same tension exists in Python. The hobbyist-hackers are using the language to write small-ish scripts, and the enterprise-scale developers are working on million-line codebases.

It's an endless cycle in all aspects of IT, the conflict between small tech and enterprise tech

Large tools from bureaucratic enterprises are useless (that's a given)

Shadow IT built around hacker tools gets the business goals through

Enterprise IT see that these tools are popular and actually meet business goals, but they didn't invent them

Enterprise IT attempts to justify itself and find something approximating the usability of the good tools from some "safe" vendor like Oracle, Microsoft, etc. After all nobody got fired for buying IBM.

Enterprise IT spends a fortune, everyone hates it, but old tools are defunded so can't be used.

Shadow IT build new ecosystem around different hacker tools to get the business goals through

And the cycle continues.

Re: Named arguments are coming in PHP 8

#87
post #40

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…

> There's a tension in PHP-land between [...] hobbyist-hacker [vs] enterprise-scale IMO the same tension exists in Python. The hobbyist-hackers are using the language to write small-ish scripts, and the enterprise-scale developers are working on million-line codebases. Unfortunately for the hobbyist-hackers, at some point (perhaps when the BDFL started working at Dropbox), the focus of the language shifted from the f…

That many developers never use type annotations (nothing interesting has happened to the type system in a long time) kind of suggests that it's not a problem. The feature is there if you want it, if you don't you ignore it.

Re: Named arguments are coming in PHP 8

#88
I've often wondered why there was no "default" keyword, so you could call a function like this:

foo('first arg', default, 'third arg');

Named parameters will do but they are more verbose.

Speaking whishes, method overloading would be great.

Re: Named arguments are coming in PHP 8

#89
post #35

The fact it errors if you over supply the function arguments is a bit worrying Adding a key to an array shouldn't be a breaking change, if you over supply a function by position today PHP doesn't error

> if you over supply a function by position today PHP doesn't error I'd argue that this it the worrying part. How often do you intentionally supply an extra argument, and how often is it an accident? I'd take the warning.

It's important to recognise what we can't do with that error in:

     25,
      'name' => 'Brent',
      'email' => 'brent@stitcher.io',
    ];
    
    function send_email(string $name, string $email) : void
    {
        //...
    }
    
    send_email(...$user);
^So this would error, even though it's a nice specification as far as the function is concerned, I'm all for strict static analysis but not at the expense of open maps

"If your program deals with information, these are among your primary problems: information is sparse, incrementally accumulated, open/extensible, conditionally available, formed into arbitrary sets in different contexts, merged with other information etc."

Post reply on HN