Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108744 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11056 invoked from network); 24 Feb 2020 23:08:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2020 23:08:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A7357180211 for ; Mon, 24 Feb 2020 13:25:15 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 ; Mon, 24 Feb 2020 13:25:14 -0800 (PST) Received: by mail-qt1-f176.google.com with SMTP id v25so7589043qto.7 for ; Mon, 24 Feb 2020 13:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=eN2aJ4o5VuRM1lWASqv30yfG0Ye7KcV10MaktMfwjis=; b=UtNYClW4QVbtlRKS8HADf7Om204IEhlxD846xbZImV+zq+3tkKg/60rAoDTsvxzpVo 5tDnRdF3HMHJ6ul4NuddYCnyex7MZ8JHop4uvq+0PABy3LVkpIrSb/JilrOjkkKeSi58 PboTGdAqnlrKCeJIfKNqnwsSKesLDZl1dFt7wZl8JUZLtQFFwo+DwEEYQK2F0+sRkv8s XsT1VtcKAjicB/MepPh/+uPtEgXjb3nkFjUmSgNjQUprVJRX/+mk8ffUlZB3afWsXPWw KLq4r3xHuY7C+fZVuVHIBavcHneqJRqvpA03uKYHJvB67Dpr5K87jaQkSyZt2VsjWUHj 7g9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=eN2aJ4o5VuRM1lWASqv30yfG0Ye7KcV10MaktMfwjis=; b=R+v7VggbwpHnPUr50R6uQVNMRdYcR3VUj0f+DiNXiuQBwpqEpO84IkH3JceJU7gDkz R2iXYPOfrT8J6XJbE9l35UbIZMfpJI46gOj4t58sdYTr1Ir4ygOEp+XsqDu5pg/m0q38 w9ITXxkNsW27znd8VoNMMipzr0SuDc58M4lr2Vst3EVR3YPAJUFowRxoBgJiG6GPTez6 SRuWuWpQU0Pv96pwTE+jGjA7IqbZPdBFg8J+WmeS2KpTrDCraPIm2wBC5gsp1HsN+iZ9 wnHp43xMC19rXtgFBhDxYQ2FxX3nrg5iXQ+26nZEQeSepSSVvJ7tYvhuaePAVKwL99L4 0oMA== X-Gm-Message-State: APjAAAWta55NJSst1gyYrQqgs3liuoc2oNn+Cl+x8T58RSlcIJAB43zE J9zmn/zT/ymwQSibMd3TBr6atsC+SJBONw== X-Google-Smtp-Source: APXvYqwdKiybdV0z/2L0B86HcTSZCM2H3ayn25+wx8LojvjF3ObuyCxF0w0UWwZsYkWYvbGJe2CblA== X-Received: by 2002:ac8:176b:: with SMTP id u40mr27132342qtk.272.1582579507984; Mon, 24 Feb 2020 13:25:07 -0800 (PST) Received: from [192.168.1.10] (c-24-131-44-78.hsd1.ga.comcast.net. [24.131.44.78]) by smtp.gmail.com with ESMTPSA id h13sm6488087qtu.23.2020.02.24.13.25.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Feb 2020 13:25:07 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: <9ebc648c-39d1-45b1-9f3d-9a799c6dec93@www.fastmail.com> Date: Mon, 24 Feb 2020 16:25:05 -0500 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <01FE7634-51EC-4D94-B4A0-62C477C096EA@newclarity.net> References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> <452D962A-C588-4F04-B000-479EBEA9B9DB@newclarity.net> <9ebc648c-39d1-45b1-9f3d-9a799c6dec93@www.fastmail.com> To: Larry Garfield X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: mike@newclarity.net (Mike Schinkel) > On Feb 23, 2020, at 12:06 PM, Larry Garfield = wrote: >=20 > On Sun, Feb 23, 2020, at 2:39 AM, Mike Schinkel wrote: >>> On Feb 21, 2020, at 6:17 PM, Larry Garfield = wrote: >>> I'm totally on board for better value object support, so that's a = good motive for me. The question I have is whether this is really a = good stepping stone in that direction or if it would lead down a wrong = path and lock us into too much TIMTOWTDI (for the Perl fans in the = room). So let's think that through down that path. How would = write-once properties lead into properly immutable value objects? Or do = they give us that themselves? >>>=20 >>> The biggest challenge for immutable objects, IMO, is evolving them. = Eg, $result->withContentType(...) to use the PSR-7 example. Would we = expect people to do it with a method like that, or would there be some = other mechanism? If the properties are public, would we offer a more = syntactic way to modify them directly? >>>=20 >>> The with*() method style requires cloning the object. What happens = to the locked status of a set property if the object is cloned? Are = they then settable again, or do they come pre-locked? >>>=20 >>> Neither of those seem good, now that I think about it. If they come = pre-locked, then you really can't clone, change one property, and return = the new one (as is the standard practice now in that case). If they = don't come pre-locked, then the newly created object can have everything = on it changed, once, which creates a loophole. I'm not sure what the = right answer is here. >>>=20 >>> My other concern is a public property (the most likely use case) = would have to be set in the constructor. If it's not, then callers = cannot rely on it having been set yet if it's set lazily. And if code = inside the class tries to set it lazily, it may already have been set by = some external code (rightly or wrongly) and cause a failure. >>=20 >>>=20 >>> How do we address that? There's absolutely use cases where setting = everything in the constructor ahead of time is what you'd do anyway, but = there are plenty where you wouldn't want to, either, which creates a = race condition for who sets it first, or tries to access it before it = gets set, etc. (This is where my repeated questions about lazy = initialization come from.) >>=20 >>=20 >> I have struggled to follow this RFC thread fully, so if I am getting=20= >> something out of context, please note that and I apologize in = advance. >>=20 >> However, it would see that rules for `write once` properties to = support=20 >> lazy loading would be rather simple: >>=20 >> 1. Write-once properties can only be updated once. >> 2. Write-once properties can only be updated within the class where=20= >> they are declared. >=20 > This is the common use case I think many envision, but nothing in the = proposal requires that. A public write-once property (as currently = written) would be world-readable, and world-writeable, once. > Separate visibility for internal and external access is a separate = matter. (Also potentially useful, but not part of the write-once = proposal at the moment.) This just hit me, so I think I will mention it. =20 The culture on the list seems not to be one of collaboration on RFC to = find solutions to improve PHP but instead waiting for someone to stick = their neck out with an RFC and then see who can shoot the most holes = through it. I did not actually expect that. I would have hoped for a collaborate = culture of the nature I am used to in local startup-oriented meetups = where most everyone is trying to help each other rather than just = pointing out that the work someone else has done is deficient and not = worthy of moving forward. If that is the desired culture that most want to have on this list, then = I will accept it even though I will lament how much better it could be = otherwise. If I misunderstand, please help me understand how wording like "but = nothing in the proposal requires that" and "not part of the write-once = proposal at the moment" rather than "the proposal does not require that = but lets's explore how adding that requirement can make the proposal = better" should not leave the impression I just mentioned above? Or maybe the problem is the mailing list is just not a mechanism for = collaborative work and we need a new mechanism. Like Github, comments, = and pull requests? Moving on... >> 3. If you want to update a property from outside the class, create a=20= >> set_() method to allow it to happen. >> 4. If you do not want it to be set externally, do not implement a=20 >> set_() method. >> 5. If you want it to be implemented externally sometimes but not=20 >> others, implement guard classes inside the set_() method. >>=20 >> I think that addresses all scenarios, no? >>=20 >> -Mike >=20 > It does not. =20 >=20 > 1) Race condition if I assume that a public write-once property is a = materialized value, but access it before it gets materialized. Can you please explain what "materialized value" means in this context? = Are you speaking in Scala again? If you mean that a write-once property just has not yet been assigned, I = am not sure how that differs from just accessing a property that has not = yet been assigned today? > 2) Race condition if internal non-constructor code wants to set the = value, but some external routine has set it first. As I said, don't let the external routine set it directly. Which you = did note. (I am interested in finding solutions in the same solution space as = selected proposals and not just limiting myself to the exact specifics = of the proposal because IMO limiting ourselves in that way has all the = bad aspects of bureaucracy and none of the good aspects.) > 3) Cloning creates an interesting and complicated case of both of the = above. Does a cloned object start with its write-once bits reset or no? = There's problems both ways. If there are problems, let us find solutions.=20 1. Only allow internal methods to change write-once properties. 2. Options: 2a. Extend clone statement to have `clone rewrite $foo` that = would allow rewriting the write-once properties. 2b. Allow rewriting once of write-once object properties until = some operation is performed to seal or lock the object (operation being = a method call, a function call with the object as param, or a statement = with the object as argument.) 2c. Don't allow rewriting of cloned objects. See if it is really = a problem. Fix it in a future RFC if so. 2d. Something else I am someone we can think of. -Mike=