Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125998 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 946821A00BD for ; Wed, 20 Nov 2024 06:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732082671; bh=+fuFUlganlHgSraMc1RNDjgXD28CMEIIiKHgRxaf3dQ=; h=Date:From:To:In-Reply-To:References:Subject:From; b=S1LQDquSpiwjTNzGth7GvhOpsIHdt7edXoHD3coAY1Oi21BN+QlTbMwhbj8TFc2dD GP5/wGhoYFeZ2L/Ef7UWbAc1EogZJ5xtiY9wx1gm3kmHc3HECycilYMCR5rFqWFQCN c5uCZ79ckiit2vkm3UzaVZDLqAS96lvgWXpD+o1hRkWP0HRtONMPwWdQjDZidLceul k+cRQ5lDD+4zWgkAaNYnZZ52oODtKpDDiLwzqlN83uW+ROU4OMr+yHC6V7U8H8YVz1 YqU3sfCsvrOEvQx2mwrQWQm9CDLDlwVdJcaTYLUnPmBEDYDCJPEU9GcjJ4YTBNyzk+ AdqdHMUBDeEMg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFD27180076 for ; Wed, 20 Nov 2024 06:04:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 20 Nov 2024 06:04:30 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 82861254016A for ; Wed, 20 Nov 2024 01:01:50 -0500 (EST) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-01.internal (MEProxy); Wed, 20 Nov 2024 01:01:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm3; t=1732082510; x=1732168910; bh=PspaJuq4Bh7e/bjhm0g4G uQRDXLLWBKiS1zUeobjGc0=; b=GWN0aAcSFdBbV6AL1qdr2KckNJo+GYMBdkExu y1wLoO6GBEF+c70cxZU3H8/QC3sNAHMtOS/LJTvVWirm77unW6mEuiZTfpcj8AUb YinYIogvtmR2whrH+nPd2BTgh9NGTlp0HQ/xpSPlwd5IZq7dcDVcOlKy1JO2sOi+ XGi4d/sJ+vsiwe+p73g9rh42pN6CzvWaQssHwqQBeTJ00XvTofJSrXvTum1sIpFx nmbH8oBEkqQuPA2rLV3JqxL3RtWXX9dALX3rgWDPvbKqbIqL3UUx7aZuWVz9LZSx OnaMnYMB8oHH/P7r2322M0bR5B+olXyK/wSbAzrE2LaHGM7Jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1732082510; x=1732168910; bh=P spaJuq4Bh7e/bjhm0g4GuQRDXLLWBKiS1zUeobjGc0=; b=AymvP3nr/+NuM/Rn1 Len/+hUt0u2xTR+eqh53/uFyD1yrCnHHxTXYrmU9uThau5Rtd2mElJCsgJ1BY1kX xhKUNpIRmSRRCZ8psXRLSlfOGN2zaf1RHobaUeqkl9InOhKGyK/nTNtqfAgT+8eQ gzsakmzdLsoqEIsZzJj90IUqhs2lTgmITAXQwf01mLMytX10oOQHoXrjgNJ/Zizv 0LbGrbnRccSuuFXof0hAYotGLvL886OvxS/U++lQfGkQ9dyNEORL0F97gQB0e1bK G+r5ToUtLt0oIEXkJ+/+pbgxkhCWvws1Cv+SebvTHPOk9Ht2DwRVnJUQv4ef0psv TTeLA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfeefgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefoggffhffvkfgjfhfutgfgsehtqhertdertdejnecu hfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivg hlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhepgfelvefgfeektedvudeljeff gfehhfeuvdevteevkeehtddtleffleffhfdtueegnecuffhomhgrihhnpehkohhtlhhinh hlrghnghdrohhrghdpphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh dpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhn thgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 09D2B29C006F; Wed, 20 Nov 2024 01:01:49 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 20 Nov 2024 00:01:29 -0600 To: "php internals" Message-ID: <1fd335a7-8764-4b26-be95-041d0bf94bbe@app.fastmail.com> In-Reply-To: References: <68eba37e-1bfe-4509-af41-112bb196415c@app.fastmail.com> Subject: Re: [PHP-DEV] RFC: Records Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, Nov 19, 2024, at 5:56 AM, Micha=C5=82 Marcin Brzuchalski wrote: > Hi Larry, > > niedz., 17 lis 2024 o 08:24 Larry Garfield na= pisa=C5=82(a): >> ... >> I can see the benefit of an inline constructor. Kotlin has something= similar. But I can see the benefit of it for all classes, even service= classes, not just records. (In Kotlin, it's used for service classes a= ll the time.) > > What visibility would you expect for inline constructor properties in=20 > service classes? Good question. If we follow Kotlin's lead[1] (Kotlin has like 3-4 diffe= rent places to do constructor-ish logic, it's kinda weird), then they'd = default to public, but you can optionally specify a visibility. So, the = same as any other property. They do not imply readonly, but Kotlin has = per-arg val/var markers on everything anyway to handle that. [1] https://kotlinlang.org/docs/classes.html#constructors >> I would far prefer assembling record-ish behavior myself, using the s= maller parts above. Eg: >>=20 >> final readonly data class Point(int $x, int $y); >>=20 >> "final" prevents extension. "readonly" makes it immutable. "data" g= ives it value-passing semantics. Any class can use an inline constructo= r. "with" is designed to work automatically on all objects. Boom, I've= just assembled a Record out of its constituent parts, which also makes = it easier for others to learn what I'm doing, because the features opted= -in to are explicit, not implicit. > > It opens a bunch of concerns, questions like why would you use "data"=20 > keyword without having "final"? > Although I like the "data" keyword very much.=20 To borrow a little syntax from Kotlin again, and randomly spitball: data class Rectangle(int $h, int $w) { public int $area { get =3D> $this->h * $this->w; } } data class Square(int $side) extends Rectangle($side, $side); (That calls the constructor of Rectangle with the provided values.) I'm generally not in favor of final-by-default. final has its place, cer= tainly, but I am firmly on team "no, you should not be making every clas= s final by default, that's just silly." Another thing to consider is ADTs. (cf https://wiki.php.net/rfc/tagged_= unions, though the text there is quite old and out dated at this point; = do not take literally.) The intent for enum cases with associated data = was that you would specify properties and types, and those would be publ= ic-readonly-enforced. That's the only option. Ilija also had plans (and= I think implementation, but I'm not sure) for reusing instances with ma= tching properties so they would point to the same object in memory, maki= ng =3D=3D=3D work. So: enum Move { case Left(int $distance); case Right(int $distance); } $step1 =3D Move::Left(5); $step2 =3D Move::Left(5); $step1 =3D=3D=3D $step2; // true That sounds somewhat similar to the restrictions proposed for Records, t= hough in context I think they make more sense on enums. I can see there= being overlap, though, so I mention it here for completeness. I'm not = sure how this all dovetails together. To reiterate, my main issue with the Records concept is that it couples = too many features together into an all-or-nothing package. readonly did= that with only 2 features, and it caused Ilija and I a lot of heartburn= and helped keep aviz from passing in 8.3. Records would couple 4 featu= res together. Once bitten, twice as cautious. --Larry Garfield