Live data from Hacker News

Named arguments are coming in PHP 8

stitcher.io

101–110 of 140 posts

Re: Named arguments are coming in PHP 8

#101
When I was learning Verilog HDL, named parameters are commonly used and highly encouraged. I wondered why more traditional programming languages didn't use this concept aswell for the same reasons the article goes into.

Re: Named arguments are coming in PHP 8

#102
post #40

Earlier quoted context omitted.

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

You'd have a point if there were any changes that are being introduced and putting developers on a straight-jacket. But I don't see this tension at all. What is recent on Python3 that makes it hostile to hobbyists? The new features are optional, it's not like Python is forcing people to adopt mypy.

> What is recent on Python3 that makes it hostile to hobbyists?

Python has become a very complex language [0], and the complexity continues to increase. IMO it's too much for people who only write code for, say, a few hours a week.

> The new features are optional

I hope Python isn't becoming a "choose your own subset" language like C++.

[0] https://twitter.com/raymondh/status/1280946969116995584

Re: Named arguments are coming in PHP 8

#103
post #101

When I was learning Verilog HDL, named parameters are commonly used and highly encouraged. I wondered why more traditional programming languages didn't use this concept aswell for the same reasons the article goes into.

I first ran into them in Python myself. After using kwargs for the first time, I wondered the same thing. While I try to limit the number of args I pass to functions and methods, sometimes it simply can't be helped. Kotlin is a wonderful example of how both positional AND named arguments can be supported.

Re: Named arguments are coming in PHP 8

#104
post #76

Ultimately every high level languages are converging to have the feature set of Kotlin, its nice to see them getting closer and closer.

Python has it since ever.

I'm talking about features in general, not just named parameters. Python doesn't have an advanced type system and yes I'm aware of mypy

Re: Named arguments are coming in PHP 8

#105
post #40

Earlier quoted context omitted.

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

OK, I'll rephrase that as "Python now has a complex typing ecosystem". That seems to be the preferred phrase - for example, it's used in PEP 586 [0].

[0] https://www.python.org/dev/peps/pep-0586/

Re: Named arguments are coming in PHP 8

#106
post #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…

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,

It's only optional when you're writing code. Even if you don't use features in your own projects you're undoubtedly going to be reading a lot of other's code, which may or may not use these features, and from that perspective added language complexity is a burden.

Re: Named arguments are coming in PHP 8

#107

"a significant impact on my day-to-day programming life"...seriously, what a bunch of shite

Exactly! Who the hell programs in PHP anymore.

every wordpress, mangento and laravel developer which probably make up about 80% of the websites on the net. wordpress alone counts for 64% of the websites out there.

https://w3techs.com/technologies/details/cm-wordpress

Re: Named arguments are coming in PHP 8

#108

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.

Having switched from 80% Java (20% about 5 other languages) to probably 75% Kotlin over the last year, one of my absolute favorite things named arguments. When you name your arguments, simply supplying them will use the default if one has been specified. If one hasn’t been specified then you must provide it when calling and your compiler/IDE will definitely let you know. I used to go out of my way with method overloa…

Yeah I'm totally fine with named arguments, I even thought they would come sooner (I've been doing PHP since 1998 so I have some perspective ahah).

And yes overloading is more about different types for me. I guess I got accustomed to it with C# and nowadays Elixir. PHP 8 has union types so I guess it will do.

Re: Named arguments are coming in PHP 8

#109
post #9

Earlier quoted context omitted.

Why not use a dictionary or parameter object when you get past 2 arguments? Or is that not a thing in PHP?

I'd think that such a solution doesn't solve but merely moves the problem. A method with N arguments, where N > 2, with a call that is messy due to the number of arguments could instead take a single argument being a parameter object where the constructor for the parameter object takes the same N arguments. A constructor with N arguments with a call that is messy due to the number of arguments ...

Aah, so then you use the Builder Pattern! Instead of one constructor taking N arguments, have a constructor that takes no arguments and N function calls to initialize the constructed values. It's cleaner because it's a named pattern! /s

Re: Named arguments are coming in PHP 8

#110
post #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…

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, It's only optional when you're writing code. Even if you don't use features in your own projects you're undoubtedly going to be reading a lot of other's code, which may or may not use these features, and from that perspective added language complexity is a burden.

Sure, but it's only confusing when reading it if it's hard to implicitly sort of understand what's happening when you're not used to it, right? Named arguments seem pretty straightforward to me, in the sense that it's relatively obvious what they are when you see them. It's not exactly like a new operator or some kind of symbol unique to the language that is almost impossible to understand without looking it up.
Post reply on HN