if we're going to accomodate variadics, and named placeholders, it complicates matters, necessarily so ... it's harder to understand and more complex to implement ...
The bit in the RFC I found particularly funny is the proud proclamation that PHP is going to be the first mainstream language with proper PFA support. You gotta wonder just why that is ;)
@JoeWatkins Yeah, I don't think it can really be materially simplified. The previous semantics were kind of simpler on a technical level, but less intuitive
@NikiC This says |> is being deprecated in Julia. I wasn't aware of this. Hmm. Going to dig around to see if that's right or if it's just outdated (several years old).
> We've been discussing a currying/partial-application shorthand for literally years now, and all of the discussions seem to have been converging towards underscore syntax, which has a long track record in Scala.
@Dharman I'd say "that's a nuisance, I've never used PHP on Windows, so can't help you"
don't get me wrong, I'm not saying "strftime() is wonderful and must live forever"; I'm just saying it's perfectly good at what it does for a lot of people
@NikiC for me, I'm willing to accept that my inability to see the benefits is a failure of my imagination, I don't write functional code and can't see how many people are doing that, because php ... but I like the idea of it, I like to see what people might do with it, maybe that's functional programming, or something horrible, I don't know ...
Extension methods only work when the LHS is an object, and you know to extend that object, specifically. And the introduce all kinds of autoload related questions.
They're also a cool feature, but much less simple than pipe.
@JoeWatkins That's a reasonable perspective to have. My own is more on the other side, where this feels like it's forcing a paradigm on PHP that does not really fit well.
@NikiC Yes. And that overly dogmatic adherence developed in large part because only classes could autoload, so functions became uncool. And because there was, at the time, no facility for doing FP style with functions, only procedural.
I remember when classes were still considered uncool. I spent 8 years convincing a major project that it was wrong to think so. :-)
@Crell Nope, or at least that hasn't been my perception :) If I use a free function included in a bootstrap file, I can already smell the incoming PR to improve this into a class.
Then the only issue left is that they're not dependency injectable... but PFA gives you something very close to DI for functions, if you use it that way.
@Crell I think that's somewhat true, people can only (easily) go through doors we open ... or smash through the wall next to the door with horrible hacks ...
I forget who said it originally, but "A programming language teaches you to not want features it doesn't offer."
And to be clear, I don't think PHP should ever go 100% all in strict FP. That would be a poor fit. But I do want to see PHP as a very strong multi-paradigm language, so we can mix and match as appropriate.
I just considered something radical like declare(experimental_syntax_features=[partial_function_application, piping]). If it ends up being used in the file without the declare then it fails to compile. This allows us to ship it, but to have a degree of freedom in changing it because it's experimental.
@NikiC Sure, but however you spell it I would like to be able to ship it this year and be able to improve it next year without it being considered a BC break. I mean, think about how much Rust iterates on things before they stabilize, and I think it's pretty great...
I wonder what problems PFA/pipes are trying to solve. My guess is 90% string/array functions and referencing a function 1:1. There are other approaches to solve those problems.
@Girgias yeah, stuff like working with zend_extension * but you never have it's definition, only that it exists. You can pass it around because the compiler knows the size and alignment of a pointer, regardless of what kind of type it points to.
For the profiler I'm working on I expect it will be a C and Rust hybrid, basically forever. It's much easier to work with the highly integrated Zend Engine bits in C, and then you ship the data into Rust and keep it there. Seems to be working well.
tbh I find pipes hard to read also, but probably because I'm not used too it ... but I know that if anyone ever tried to get that code past me, I'd slap them so hard, they might cry ...
but that makes it hard for me to see the benefit, it looks like a nice way to write horrible code, but at bottom, it's still horrible code that I wouldn't allow right now ...
I just feel like scalar methods would be a more natural fit. People are already used to that syntax and $a->b() already is sugar for A::b($a) in pretty much all languages.
I don't think you can substitute any character and avoid this; if I were to drop in and propose using ? it would have the same issue, just a different scope.
So basically they have to get consensus that it's worth breaking code for the feature.
I really wish we could use _ but yeah, not happening. Thanks gettext.
@Crell well sure, but that doesn't mean we should seek to legitimize it ... you just said a few minutes ago that habits evolve with the features we provide, and providing a feature that legitimizes thinking like that ... I'm not a huge fan of ...
I think the piping version is easier to read, because you can see the flow at a glance much easier. In the imperative style, you have to check if the calls in the middle actually hook up as parameters as expected.
With |> you can tell it goes top to bottom, no "sideways" edges or whatever (not sure on terminology).
Real code out of a Symfony app that TYPO3 uses:
public function prepareRequirements(Collection $collection): array
{
$result = $this->formatVersions($collection);
$result = $this->groupByCategory($result);
$result = $this->sortByTitle($result);
return $result;
}
What PFA and pipes would allow instead:
public function prepareRequirements(Collection $collection): array
{
return $collection
|> $this->formatVersions(?)
|> $this->groupByCategory(?)
|> $this->sortByTitle(?);
}
(No free standing functions were harmed in the copying of this example.)
@Crell I would not start mixing methods with pipes. As mentioned, $a->b() is already sugar for A::b($a) which makes $a |> $b->c(?) sugar for B::c($b, $a). To me that's not at all better than the version above.
this may be unfamiliarity, of course I can read it ... but at some point, a junior is going to work on this, and I know what is going to take longer to explain ...
You have very little faith in juniors. :-) Again, people learn what they're exposed to.
I still deal with people who whine that anything with objects is too complicated and advanced and requires a CS degree and is too hard for "normal developers." Those people are wrong.
I wouldn't expect a junior to be familiar with this kind of feature, I don't expect them to be familiar with most of everything, because junior ... that means I have to spend time explaining it ...
@LeviMorrison Does it though? The dataflow is practically the same ($result -> $result, or |> to ?). Nothing really changes, the result value is just unnamed.
you know people read code in different ways ... what I reduce it too mentally is not likely to be the same as what you reduce it to, what I reduce it too is almost certainly not going to be what a junior reduces it too ...
The question at the moment is if there's anything we can do with partials to get people more confident that the benefits outweigh the complexity. I think they do, and I don't see how the complexity can be reduced without basically not doing it at all.
I think the benefits are mostly to be discovered ... sure it might benefit pipes, and we might have some use cases in mind, but for me I don't know what the real benefits are yet ... but do know how complicated it is and I can't weigh an unknown quantity against that ...
essentially, you'd have to prove nikita wrong ... that is not possible, nothing he has said is incorrect ... it is as he describes it, and he understands the complexity like I do ...
I'm willing to ignore that complexity, because I think people will do cool things, and it opens a door, and expands horizons, which I like ... but we can't say other than the use cases we've given, anything more to justify that complexity ...
Just for the sake of knowing... if partials fails, as it looks like it might based on voting so far, there's nothing to stop Nikita from immediately invoking a vote on "..." only, yesum? The overlap won't cause any problems
The point is readability and chaining, JS's object based approach is vastly more readable than PHP's procedural approach in this regard IMO, the style in general is favoured by every modern major language... except PHP
and it would finally make people shut up about PHPs argument orders, because it would eliminate most of them :D
@Crell i posted to the list with my reasons to vote no. I believe we shouldn't make the language more complex around calling functions. Take the "four" example and how to call it 5 different ways using partials, it is a fun academic excercise to have, but it will confuse the hell out of beginners.
@beberlei There's technically nothing partials do that you can't already do with short lambdas. They're just more verbose and harder to read than partials are.
@beberlei I disagree. By the same token, short lambdas are unnecessary because long-closures can do everything and make it more obvious what's going on.
@MarkR well, don't get me wrong, if I haven't used something for a while, I might look at the doc - but I know to look at the doc, so I don't see the problem ... and if your ide is doing it for you, same result - you don't actually expend any effort on the order of arguments either way ...
Without wanting to be "that guy" .... JS, or specifically TS, is now a more expressive language to write than PHP in practically every way. But it has 2 major drawbacks, one is no runtime type checking, and the other is 'number' vs int / float.
PHP's remaining advantages are it's vast server-side ecosystem, shared nothing architecture and, dare I say it, some of it's magic.
@Crell the use of ... and delayed exeution did add more to the proposal than I was expecting, but even just with ? it would have been on the fence. I think you don't really need partials that often in code, so when you come across a use-case then a short lambda is fine enough for me. whlie its different for short lambdas in general, you find a lot of cases were they make sense to use over a closure