Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112717 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10969 invoked from network); 2 Jan 2021 22:36:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Jan 2021 22:36:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8E5311804C6 for ; Sat, 2 Jan 2021 14:12:08 -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 ; Sat, 2 Jan 2021 14:12:08 -0800 (PST) Received: by mail-lf1-f43.google.com with SMTP id o13so55809098lfr.3 for ; Sat, 02 Jan 2021 14:12:08 -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; bh=rOYpp1FuCBrjkSzlAmY54xaPNf2iArSH5JBx946hrSM=; b=U49cW9iqWSgn2Kt4Su2ywMo38jDEKxQnWVX5rlQwvbNtFTOanBs8eOhndFOFLRnN7P 3IFnsDb/sDL9S0DEt2qSM4JNHHssVNAApeSTlm0Vw8p00Bd/Q9hHUco7AeK2UVZItCqO oo5DJFTN+GpyaRVTAGOSlwJEkpC/dxVFCjidSScjRQaYSVj1+d1fxZxgMeAvjc8ALnuL uu7zS6jktseR1OcmPrbb6J5pqbq1rpsIFXcCncca0LxGvz6XAm9eL6TgafVLpEOUT1iF PetEp6VDcPrOeH0cRJg7WvwnvxcAl2XVv+IyWkTyGNwJfUd6wdq+kSgFwU7ndRVrRjOB ThvA== 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; bh=rOYpp1FuCBrjkSzlAmY54xaPNf2iArSH5JBx946hrSM=; b=ZFoXSZyu2a/lAoRuB97Kq9Z21Re++Qu1FNMlp4Fw4XNRGLeFgthBkEI3tNDj9ZsO0j dhLsvKPwE8iNOtRssTPMVyCJnyJVgNTuu9bvxGT8fL7eOV0UO1RK65+HRSqc0D+j0F72 h1aCloagWX/bBwJOWxdj2RXtZ+uykiP9rCruIR9iVDKrRqee6N0m8oOWQnJ/dsUSzy6+ NxqoN9pTPu1f9cAzfIQhEBr4VnHCc5YgedxGxV2MmBroFMLU3NmTZCkcTwzSxnSXcMJi bUBaZ6W1Wz5lV7BDn8Shk29l4e5wgQ/Tpt+nSVPIsYvG4LlcsBwbfhfYlvMJCFqxd2x6 JS0Q== X-Gm-Message-State: AOAM5302kjJ838sYOIQX9axCM/667eM2F5aAZbSyOhGdF49WbvhTpZJm BHK5WC0Kl8vLh/HvPsJy0jm8KD82x4LCYXGjNhe9j8fwW74= X-Google-Smtp-Source: ABdhPJx2o2udNqvlgaOito/qHH3JdEJsnFyI/nc9vyMd0Wfkmux83nGFbiZUvryEMkgbmglN+qnJEe3EbUZ6joU/hxk= X-Received: by 2002:a05:6512:3048:: with SMTP id b8mr30265319lfb.421.1609625526333; Sat, 02 Jan 2021 14:12:06 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ab3:7110:0:0:0:0:0 with HTTP; Sat, 2 Jan 2021 14:12:05 -0800 (PST) In-Reply-To: <6f51556b-a566-45d2-939e-3d6c3441eb00@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> <0C621FEF-B76F-41F5-A5A8-E6F24D69DD3D@pmjones.io> <6f51556b-a566-45d2-939e-3d6c3441eb00@www.fastmail.com> Date: Sat, 2 Jan 2021 22:12:05 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" 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 21:25 GMT, Larry Garfield : > On Sat, Jan 2, 2021, at 12:56 PM, Rowan Tommins wrote: >> On 01/01/2021 20:31, Paul M. Jones wrote: >> > The complaints against the incomplete and inconsistent immutability of >> > PSR-7 have merit. >> >> >> The big mistake of PSR-7, in my view, is mixing immutable objects with >> streams, which are inherently mutable/stateful. I wonder if there are >> any lessons to be learned there in terms of what kinds of immutability >> the language should encourage / make easy. >> >> For instance, is it better to constrain entire objects to be immutable >> rather than individual properties? And should there be restrictions on >> what you can declare as immutable, since "immutable resource" is largely >> nonsensical? >> >> Or is it rather a reflection that building purely immutable >> implementations is hard, and the language needs other facilities >> (monads? ownership?) to mix in those parts that don't fit? >> >> Regards, > > I rarely hear that called out as a PSR-7 complaint specifically, in > practice, but moving on... > > IMO, it's better to put the focus on immutable properties. There are use > cases where you want only some properties to be immutable, but not the whole > class. If you do want the whole class, then marking all the properties > immutable is effectively the same thing. > > Though, again, in practice, at least in PHP, I don't think immutable > properties should be the goal. Asymmetric visibility lets us built safely > immutable-from-the-outside objects that are "up to you" on the inside. I > think that gives us a better end result given the nature of PHP. In other > languages that wouldn't make as much sense, but PHP is what it is. > > Copy on write makes "immutable data structures" not something we need to > build explicitly; we get "close enough" for free. If you really wanted to > micro-optimize the memory and CPU usage further than that... go build it in > Rust instead. Correct me if I'm wrong, but copy-on-write is only beneficial with values, not references to values (objects)? When you clone with a `with` method, you always write, so you always have to copy. And objects are already free to pass around without any copying happening automatically (as is the case with arrays, which have value semantics, which is why copy-on-write was implemented to not copy needlessly when an array is only read from). Olle