Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112708 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21085 invoked from network); 2 Jan 2021 00:16:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jan 2021 00:16:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 36F9D1804A8 for ; Fri, 1 Jan 2021 15:51:39 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 1 Jan 2021 15:51:38 -0800 (PST) Received: by mail-lf1-f43.google.com with SMTP id h22so51144647lfu.2 for ; Fri, 01 Jan 2021 15:51:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=VBkAh0TVo8+LiN5YInmRFBOrjbDGGXIEJkVh2XgiIWo=; b=a+4J4yR4cRfyLBlYe2OI/nro+wTz7bziImjsijE+5ZQyF767kI+yZz4z0wzHsN401i /I9DQd2Oq9RSsWx5ILo68aKjhCiw2gA143IzIM7EEx9PfIZGpuFLGTuh5hFmtVFjTGAw UQimMxG16iMG/Yd7nqgA7XBJXU0EWuBKW82tg7HY60PPDH6r2fcCeoV9uLJqGJotjwxB B+Xd+iYCbZqvoyMDE6WamOs1NfCUjD8NagweoTDQJ2/ldAhiswbJwCIBj/DMZSUWE9re J5nFDpnFgmpUn4VMLkub6YUrDXuoxWJwVUGbXYBx0thd40vKa1VynjCOhT5a65yzG+gj 82RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=VBkAh0TVo8+LiN5YInmRFBOrjbDGGXIEJkVh2XgiIWo=; b=tMgqknkPWvzzluIMsK59iNVbl4tRMqDW0gX2jhZVHMT2whsAF+yOX83byIoJ5d36UZ NlymOknndw+TmSTvTNI65No2UkhtPw7RlrRKWh4iBFupUVj2dbFzJ62zSwY8ED+4RqZ9 oPiGhUFpMCcGn98HdjV366uxwkekGDir+khn9gXnKQS61MTYjkVR8/msb8mFzsD8gLqQ z3I3AzXMs9SoSDGG1R1enBNzXHB0GgXXANWbQtY6lF9ZD6OcfhusWrzQsCzdSuxAevA7 K1G+HFj4tPop2PaOD/NQpycBFqsq2kRQUInwwxQohqYCr0Hojd4PBnMhOWYjNvXcPUUb zWkQ== X-Gm-Message-State: AOAM531caMOyBEap1jzIO0jmfGVZQzm3IWFcasDWYMNbR7uVaYP/Djo+ 4tnJPI5aueV0DSSlwFbj+o5WnN1stev0tY9uW6DrHw4DIpE= X-Google-Smtp-Source: ABdhPJxo9QJEFc+X14LVm5TxgH342l2rrZ/l0KLrLQv7n8Kp+VJwm8OYv15dBOKy/6RTn31P4lFeIealJulPJ/bH1nw= X-Received: by 2002:a05:6512:208c:: with SMTP id t12mr28894823lfr.165.1609545096312; Fri, 01 Jan 2021 15:51:36 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ab3:7110:0:0:0:0:0 with HTTP; Fri, 1 Jan 2021 15:51:35 -0800 (PST) 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, 1 Jan 2021 23:51:35 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Analysis of property visibility, immutability, and cloning proposals From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2021-01-01 19:14 GMT, 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 an >> >> 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 clone >> > if >> > the values were implemented as mutable. Switching to methods again may >> > 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 mess >> > up the universe... >> > >> > >> > Regards, >> > >> > -- >> > Rowan Tommins >> > [IMSoP] >> >> 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. :) >> >> Olle > >> The web dev discourse is >> one-sided with regard to immutability, > > Yes, if you've heard any of the regular whining about PSR-7 being an > immutable 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 immutabilit= y > in PHP in syntactically clumsy and ugly. We want to fix that, and that h= as > to include some means of "give me a new value based on this existing valu= e > but with some difference." (aka, exactly what with-er methods do, althou= gh > I agree entirely that if you have the option of less generic names, use > them). > > So, can we get back to the original post, which is proposing specifics of > the tools to make that happen? :-) (Asymmetric visibility and clone-with= , > specifically.) > OK! I like that you connect higher level design patterns with language design. This is the way to go, IMO. Personally, I'd prefer support for the Psalm notation `@psalm-readonly`, which is the same as your initonly. Clone-with makes sense too, as this construct is already supported in multiple languages. The exact notation doesn't matter that much - my personal choice is OCaml {record with x =3D 10} over JS spread operator, but OCaml is pretty "wordy" in notation in contrast to the C tradition that PHP is part of. Reintroducing "objects that pass by value" is a hard pass from me. The way forward is immutability and constrained mutability (ownership, escape analysis, etc). Psalm also supports array shapes - maybe this can be investigated as an alternative? Since PHP has no tuples. I'm not convinced the added complexity of asymmetric visibility is powerful enough to motivate its existence. Feel free to prove me wrong. :) My choice here would be namespace "internal" (also supported by Psalm already), but this requires implementation of namespace visibility, a PR that was abandoned. And also, happy new year! Olle