Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112703 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96794 invoked from network); 1 Jan 2021 19:39:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Jan 2021 19:39:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4673F1804D4 for ; Fri, 1 Jan 2021 11:15:06 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 1 Jan 2021 11:15:05 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 35A467C7 for ; Fri, 1 Jan 2021 14:15:04 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Fri, 01 Jan 2021 14:15:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=SaRe+V7KnRypK68d/eMLb36zlopgj7pKdOrqWJLkO 6I=; b=DF6eMCthNjAL3N9JBjhrDUIk1SMlcsFm6MZMlP1dTA0dGSJ7CpglS7wY7 CdgCu5gfFdRwtf4QDznRmnhagn+EE0B93N+Prvq/7Xijz1PMY9a13rIJOsz2qOIY VagtChhyzc1uU2dfrXhzjrbkJKeuB/6USkHjRhLYnd3+Mnw6VihifBfwXaFX4GQB 9tCHOVv0cighLI//Q5DLJf4IuGqDzfx2wZUjtIcKujfj9APhe0vmg5O8Rl1FFxe1 UKeMNlY7KyNv2W3nYHrzL+BouAHzcXNHyQVq8GvjsF1BFsEIAwsTr1Qrx1I8a8yC HrRK4FqBsxLTJqEW6H4DZX0Y0rxyA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvjedguddvgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 18B0814200A2; Fri, 1 Jan 2021 14:15:03 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <1d0abb04-4987-43a9-85bc-bccc3bd6be9a@www.fastmail.com> <03108284-740a-4a5d-130f-15b2e67e9df9@mabe.berlin> <459d7ff7-e553-dce9-7d43-c3b1e772e572@gmail.com> <7f4fe9ca-1c20-6f69-cef0-a9718af742a3@gmail.com> <30906866-1971-8395-05a0-fd78d054bb89@gmail.com> Date: Fri, 01 Jan 2021 13:14:42 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Analysis_of_property_visibility,_immutability,_a?= =?UTF-8?Q?nd_cloning_proposals?= From: larry@garfieldtech.com ("Larry Garfield") On Thu, Dec 31, 2020, at 8:04 AM, Olle H=C3=A4rstedt wrote: > 2020-12-31 12:37 GMT, Rowan Tommins : > > On 30/12/2020 18:42, Olle H=C3=A4rstedt wrote: > >>> To put it a different way, value types naturally form*expressions*= , > >>> which mutable objects model clumsily. It would be very tedious if = we had > >>> to avoid accidentally mutating the speed of light: > >>> > >>> $e =3D (clone $m) * ((clone $c) ** 2); > >> Using a variable on right-hand side does not automatically create a= n > >> alias, so in the above case you don't have to use clone. > > > > > > Whether or not the type system forced you to, you'd have to use clon= e if > > the values were implemented as mutable. Switching to methods again m= ay > > make that clearer: > > > > $c =3D new MyNumber(299_792_458); > > $m =3D new MyNumber(10); > > $e =3D $m->multiply( $c->square() ); > > > > If multiply() and square() are mutating state, rather than returning= new > > instances, $c is now 89875517873681764, which is going to totally me= ss > > up the universe... > > > > > > Regards, > > > > -- > > Rowan Tommins > > [IMSoP] >=20 > Yes, of course you can find use-cases where immutability is a better > choice, just like I can find use-cases where (constrained) mutability > is better. The point is not to replace one tool with another, but > rather adding another tool to the toolbox. The web dev discourse is > one-sided with regard to immutability, I think. Wish I had time to > implement a PR to Psalm to show something more concrete... Again, if > you only have a hammer, everything looks like a nail. :) >=20 > Olle > The web dev discourse is > one-sided with regard to immutability,=20 Yes, if you've heard any of the regular whining about PSR-7 being an imm= utable object you'd think it's one-sided in favor of mutability. ;-) As you say, the point here is to add tools. Right now, doing immutabili= ty in PHP in syntactically clumsy and ugly. We want to fix that, and th= at has to include some means of "give me a new value based on this exist= ing value but with some difference." (aka, exactly what with-er methods= do, although I agree entirely that if you have the option of less gener= ic names, use them). So, can we get back to the original post, which is proposing specifics o= f the tools to make that happen? :-) (Asymmetric visibility and clone-w= ith, specifically.) --Larry Garfield