On Sat, Aug 24, 2024, at 11:49 AM, Bilge wrote:
> Hi gang,
>
> New RFC just dropped: https://wiki.php.net/rfc/default_expression. I 
> think some of you might enjoy this one. Hit me with any feedback.
>
> This one already comes complete with working implementation that I've 
> been cooking for a little while. Considering I don't know C or PHP 
> internals, one might think implementing this feature would be 
> prohibitively difficult, but considering the amount of help and guidance 
> I received fromĀ Ilija, Bob and others, it would be truer to say it would 
> have been more difficult to fail! Huge thanks to them.
>
> Cheers,
> Bilge

I am still not fully sold on this, but I like it a lot better than the previous 
attempt at a default keyword.  It's good that you mention named arguments, as 
those do replace like 95% of the use cases for "put default here" in potential 
function calls, and the ones it doesn't, you call out explicitly as the 
justification for this RFC.

The approach here seems reasonable overall.  The mental model I have from the 
RFC is "yoink the default value out of the function, drop it into this 
expression embedded in the function call, and let the chips fall where they 
may."  Is that about accurate?

My main holdup is the need.  I... can't recall ever having a situation where 
this is something I needed.  Some of the examples show valid use cases (eg, the 
"default plus this binary flag" example), but again, I've never actually run 
into that myself in practice.

My other concern is the list of supported expression types.  I understand how 
the implementation would naturally make all of those syntactically valid, but 
it seems many of them, if not most, are semantically nonsensical.  Eg, `default 
> 1` would take a presumably numeric default value and output a boolean, which 
should really never be type compatible with the function being called.  (A 
param type of int|bool is a code smell at best, and a fatal waiting to happen 
at worst.)  In practice, I think a majority of those expressions would be 
logically nonsensical, so I wonder if it would be better to only allow a few 
reasonable ones and block the others, to keep people from thinking nonsensical 
code would do something useful.

--Larry Garfield

Reply via email to