Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112728 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82061 invoked from network); 3 Jan 2021 14:52:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2021 14:52:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2B4D81804D4 for ; Sun, 3 Jan 2021 06:28:27 -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=-0.7 required=5.0 tests=BAYES_05,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-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 ; Sun, 3 Jan 2021 06:28:26 -0800 (PST) Received: by mail-lf1-f42.google.com with SMTP id 23so58523913lfg.10 for ; Sun, 03 Jan 2021 06:28:26 -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=P6m9NMRN1v96tlI6eA2o77vsVYvfIKHN5ruLszXIwMs=; b=G2nogiXYzctrZC4F7a1yPz6sLi92xbTJywOG3Sqxu8tBy348YM02zvVMcLTMu50e3r P9Zlmzg95E1gfrWFqaS65/z7uQfYEFyC2YHEoHiJjLJc0uPNyJeBuxcFnlXbtA40JhD8 VtR5AiJy5S4M2NNP82NImm2hwVHx1lUPXpTJDvbjRLGyJrfMxGqrm7GVKvUg+UJwWkDo T8TYbUuj3yZieafEZCF1anHA1S1rc08SpdxIWJdqdcd2sukeUvCHjukVVwlQ1zEGu3aT fBE845LYliRgEQBt1EGId55FsaabDdWMeP/YHl3eIgVa8fdfPZk4bZ8NcFmMk667hYQQ zXHQ== 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=P6m9NMRN1v96tlI6eA2o77vsVYvfIKHN5ruLszXIwMs=; b=LftSDBAxU7UBReE16HQeWCJdjts6nWU6DekfFIPahVInDgDhMFxnHYYiHtRBtir3H9 M9wHkDfL8SKm5U+G7PYoUfuW/Vm0/e2YqtWzzem8g4qEDpU7C3O+2MXo8CM9H4HYauwk 0/mC67X/b00KWSbBTexwT1phg6lF9yoGk3f9PEQU5RqjBpzBtrpYhs/anWnT/STFzBS5 9rLChFSOajZ6bkhm/WR/3HFQhHTvrw7oHleZDh7b1gw11EmK1mlRWggyhXHTZLZsom3w +EmCZBD9BfKEZOreCk93EtNkUSjWQ9mEog9sYvZgWV1yrvMYRYbTGD9Isb4YY2rsGO16 c94Q== X-Gm-Message-State: AOAM532AHOjICZus5yeT/O8itryMSvJbVMTr+YzQWfYuhKVVDcqv5Kro 5N3e9zk11AImJWd6S4VdkwIY5aTt5DnM2Wzb2FOxG8Zb83E= X-Google-Smtp-Source: ABdhPJwLSt1GoZEVm10fpy2+SVTc7T/Dm40EfOhE/GEVoaALuxdG6nBdQzHLjIbyWcW05zPh5sEBiqbD3BNftUpwT9Y= X-Received: by 2002:a2e:9f06:: with SMTP id u6mr31577598ljk.194.1609684103096; Sun, 03 Jan 2021 06:28:23 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ab3:7110:0:0:0:0:0 with HTTP; Sun, 3 Jan 2021 06:28:22 -0800 (PST) In-Reply-To: <34d6a045-f7c3-4a77-8b22-378e84b2d1f9@www.fastmail.com> 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> <34d6a045-f7c3-4a77-8b22-378e84b2d1f9@www.fastmail.com> Date: Sun, 3 Jan 2021 14:28:22 +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-02 16:06 GMT, Larry Garfield : > On Fri, Jan 1, 2021, at 5:51 PM, Olle H=C3=A4rstedt wrote: > >> >> 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 >> > immutability >> > in PHP in syntactically clumsy and ugly. We want to fix that, and tha= t >> > has >> > to include some means of "give me a new value based on this existing >> > value >> > but with some difference." (aka, exactly what with-er methods do, >> > although >> > I agree entirely that if you have the option of less generic names, us= e >> > 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! > > Happy New Year! > > I agree that "objects, but passing by value" would not be the right > solution. I used to think that would be a good part of the solution, but > eventually concluded that it would introduce more complexity, not less. > Eventually, everything people wanted to do with objects they'd want to do > with "Records" (for lack of a better term), and if they pass by value but > are still mutable then you have a weird situation where sometimes changes > propagate and some don't (depending on if you have a record or object). > Making it easier to use objects in a value-esque way will get us closer t= o > the desired end state. > > I think the tldr of my post is this: A single "immutable" flag (whatever > it's called) on a class or property would require having lots of holes po= ked > in it in order to make it useful in practice (mostly what "initonly" woul= d > do), but those holes would introduce other holes we don't want (cloning a= n > object from the outside when you shouldn't). I new language feature needs to be both simple and powerful - it's not enough to be only powerful. A second problem I see is how asymmetric visibility would affect the readability of a class, putting extra strain in understanding it. Thirdly, how does PHP differ from FP languages like OCaml and Haskell in this regard, neither who uses visibility in this way? What's acceptable in those languages that would be unacceptable in PHP? Olle