Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125211 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 7EF021A00C5 for ; Sun, 25 Aug 2024 14:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724595053; bh=JCWb5ZgdHMNA8kRKVgqjaIfzUY6G0TyBL7CWgadkz3g=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Iydsrn5B2awEW4r+HB/YQqFBFgIcSwoYVu4ksxQqlg0Hl2kboTo/l3DyIjCjBeZsi ajmos6BC6OXZVxuB/FMVZ53+4Jlw34VYHWWt/0KhfHjQcQ1vTagieiwe4OSFErkEDb 7Mr6TW7IWiZdpp81ItrlsI1sAzcx2fvUVGfKiOEA4wrOEtriER1bp/dSjutSBQuWeo WWFte+96Pj9fpH6PjJLauRbpmeOvdY1zjWU0Ei6pfeKBwdO2NRwzuG9HBgRNyTV3B7 rj2xsaV4VGRy5fRpSvrAeKQEkRMVM5dlt03Vq03xytXIo6aH47S9N3DcY7Q1AOfNNm l/3gx6eMLzP8w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8544B18038D for ; Sun, 25 Aug 2024 14:10:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 25 Aug 2024 14:10:48 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 41E1C1146D4C for ; Sun, 25 Aug 2024 10:08:56 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-03.internal (MEProxy); Sun, 25 Aug 2024 10:08:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1724594936; x=1724681336; bh=ATtbE6WsBv k4y7z0eGUmzvWYmnI6O1OQ+kAswZfG/ZI=; b=CD0ZSmGmCDqf91IjgaIhY+ZAge xtRFMfRL0Wly+Hud4mrNZI9lqhN6FLOSYqvhyn8HDdFs0OkeC3+KKEBBrA05DZud S58Q8j9U6JMEPYxD+qDlyeCIKjvzytiuCqPqNFVv/bspkrLcG7sH+Cm26kIboXeN YAQbs/G7NXcg3bVtQ8DdGfDI9hT4Y48F8JO2VqSTVWu9s0cZqDpTv64CtH21JLeN lake+7mevvmMlgJx9VyO89zH4wZC7NjneksFkfFVBU2HMtOevgBWUJvVXTNYgCRB +2Ovqpi3bBwrP6gF2WIuhdIKUa54k1a0ipu13dBGvY0SIPvxYfXn60r3lsAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1724594936; x=1724681336; bh=ATtbE6WsBvk4y7z0eGUmzvWYmnI6 O1OQ+kAswZfG/ZI=; b=LgalUZn1at6+I4k4Ri7FkzbQeNmU+Oxnpty2eRMgCLAG CIuNbixwEq4ieg+t1lNxVOrWnAF+yY05jPwMO87vXvGHe8t+nBvJCn8p6n4pkP+2 oPSc+T9YDWTEAhV6rb+WhDpX+MBTO3hVcSFOYJjSgi2jbof2FxZ2YKOZ0FR0CeKl lQ5kzEJSsRf+1IeymDaLB0t7OkTe3jn17znfj4fkxOkKx1Huuuk6myW1lvV8Z27k qb74i69fnQgYgTpFAAGeG1eiakPtVZtQZy6yoEYVW/+NVHwsfaw+01tmzWqwee07 1xdubdfqdffgQMCxKP9QkyGZAhxZrSr0QvMGItoxZA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddviedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefoggffhf fvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcu oehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpeelkeehtd fgfefhleeilefggeeihfekvdelfeejtdfflefhheehfffgudetuddutdenucffohhmrghi nhepphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedu pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsth hsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 082DD780065; Sun, 25 Aug 2024 10:08:55 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 25 Aug 2024 16:08:35 +0200 To: internals@lists.php.net Message-ID: <33d3516e-ec55-43ea-a38f-050060852389@app.fastmail.com> In-Reply-To: <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com> References: <0c8ed5d6-5507-4c41-8d7f-05d14ba8aa4c@scriptfusion.com> <0cfd3a28-3cb0-4478-85fb-cf086d8e5c66@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Default expression Content-Type: multipart/alternative; boundary=61b7aa49b4d14ca3a8f57cc465b4bd64 From: rob@bottled.codes ("Rob Landers") --61b7aa49b4d14ca3a8f57cc465b4bd64 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Aug 25, 2024, at 15:35, Larry Garfield wrote: > 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=20 > > think some of you might enjoy this one. Hit me with any feedback. > > > > This one already comes complete with working implementation that I'v= e=20 > > been cooking for a little while. Considering I don't know C or PHP=20 > > internals, one might think implementing this feature would be=20 > > prohibitively difficult, but considering the amount of help and guid= ance=20 > > I received from Ilija, Bob and others, it would be truer to say it w= ould=20 > > have been more difficult to fail! Huge thanks to them. > > > > Cheers, > > Bilge >=20 > 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 name= d arguments, as those do replace like 95% of the use cases for "put defa= ult here" in potential function calls, and the ones it doesn't, you call= out explicitly as the justification for this RFC. >=20 > The approach here seems reasonable overall. The mental model I have f= rom the RFC is "yoink the default value out of the function, drop it int= o this expression embedded in the function call, and let the chips fall = where they may." Is that about accurate? >=20 > 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. Potentially the most useful place would be in attributes. Take crell\ser= de (:p) for instance: #[SequenceField(implodeOn: default . ' ', joinOn: ' ' . default . ' ')] Where you may just want it to be a little more readable, but aren't inte= rested in the default implosion. In attributes, it has to be a static ex= pression and I think this passes that test? At least that is one place I= would find most useful. Then there are things like the example I gave before, where you need to = call some library code as library code and pass through the intentions. = It also gets us one step closer to something like these shenanigans: function configureSerializer(Serde $serializer =3D new SerdeCommon(forma= tters: default as $formatters)); Where we can call configureSerializer(formatters: new JsonStreamFormatte= r()). Some pretty interesting stuff. >=20 > My other concern is the list of supported expression types. I underst= and how the implementation would naturally make all of those syntactical= ly valid, but it seems many of them, if not most, are semantically nonse= nsical. 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 a= t best, and a fatal waiting to happen at worst.) In practice, I think a= majority of those expressions would be logically nonsensical, so I wond= er if it would be better to only allow a few reasonable ones and block t= he others, to keep people from thinking nonsensical code would do someth= ing useful. I'm reasonably certain you can write nonsensical PHP without this featur= e. I don't think we should be the nanny of developers. =E2=80=94 Rob --61b7aa49b4d14ca3a8f57cc465b4bd64 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Sun, Aug 25, 2024, at 15:35, Larry Garfield wrote:
=
On Sat, Aug 24= , 2024, at 11:49 AM, Bilge wrote:
> Hi gang,
<= div>>
> 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.
>
&g= t; 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 
> prohibitive= ly difficult, but considering the amount of help and guidance 
<= /div>
> I received from Ilija, Bob and others, it would be t= ruer to say it would 
> have been more difficult t= o fail! Huge thanks to them.
>
> Cheer= s,
> 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 explici= tly as the justification for this RFC.

The = approach here seems reasonable overall.  The mental model I have fr= om 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 w= here they may."  Is that about accurate?

My main holdup is the need.  I... can't recall ever having a sit= uation 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.

Potentially the most useful place would b= e in attributes. Take crell\serde (:p) for instance:

<= /div>
#[SequenceField(implodeOn: default . ' ', joinOn: ' ' . defaul= t . ' ')]

Where you may just want it to be = a little more readable, but aren't interested in the default implosion. = In attributes, it has to be a static expression and I think this passes = that test? At least that is one place I would find most useful.

Then there are things like the example I gave befor= e, where you need to call some library code as library code and pass thr= ough the intentions. It also gets us one step closer to something like t= hese shenanigans:

function configureSeriali= zer(Serde $serializer =3D new SerdeCommon(formatters: default as $format= ters));

Where we can call configureSerializ= er(formatters: new JsonStreamFormatter()).

=
Some pretty interesting stuff.


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

I'm reasonably cer= tain you can write nonsensical PHP without this feature. I don't think w= e should be the nanny of developers.

=E2=80=94 Rob
--61b7aa49b4d14ca3a8f57cc465b4bd64--