Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125986 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 08DA01A00BD for ; Tue, 19 Nov 2024 11:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1732017588; bh=2MEywigKvpUsNqER1brAl7YyeZypXpqTQbDFbPsNHqI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=A4rDL5l5d1kJtigLBpuwW+uVpImcCH4wWEooYWQ5k4VpdvmplN6B1FJcD4qJY+Stt cXgc46jyu7BARfd5DCpbPnyuC7or+Hm70MYxRW2/At4E2fMR4SNwIfQdfSyCq4ernD +jKsv8MAKnzEq7dVscqXNkuwBfxoEZ38Wcnr/b5x+yZhw/QIrosFbFBgh2TDZnzFJC F2G4r74ZuotsLEpc99XS+zvi8y/DBmzM9gRIKGGbLCyMLbSlXc3/ZEmnRcNzz2ddkv FX/iqAawfVQxgfPKrbMXL5uokPbPqBzz5fB4blu1cMidW+Lx275aquoIhzPPxw9P6a g6B1RcqWxUasA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D50F8180056 for ; Tue, 19 Nov 2024 11:59:47 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 ; Tue, 19 Nov 2024 11:59:47 +0000 (UTC) Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6ee676b4e20so10020627b3.3 for ; Tue, 19 Nov 2024 03:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732017428; x=1732622228; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=otLAwhN8bTLzDoQE9Ljyi3pQNCN8i3FaohlLVrEH09w=; b=VsIygpym/2O/LscdN2TM5jmvL3NSZrNv4cdOaBWkxz0Cgafc+NAfT0tpiFP9O9F5Ky jzP6nrqFDTpcLzIIu3mRDXdDTVe1wxzZFTJpdyTUFZeIvVmLcAyReqRMrk994dqgJja/ RDwwkjtu5YUNG8BIdKyZacDe3L9iliyWs1TZCSiUbcIbXJcykwPRw1SueE7gWDBvChK4 zJF7M77HcEbrp4Mbxx735OoXHdoyWL13dxriWo7leERQVipJsB74wuArdnq74lbnbvF3 cYttmymat2ntt4EPa/UEvRcRT4NedTjlJYEfFg6t0vYGEyX8N+8BdCufdbDiYcC8QJav eP+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732017428; x=1732622228; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=otLAwhN8bTLzDoQE9Ljyi3pQNCN8i3FaohlLVrEH09w=; b=KOC6nK8HFkIZ2V7FkXuJUJYLIXcPN2NfGJ7j+CG2AXLDIKQxcAtGo/SLwVITT6K8zO i7VESJqaolxE8hNJUh/A1pQfp/pmWfXDDHoM150Wx7Cn6KPgJI8LAPoi+e//rEXayQqO hHDozXVMaFItDKeQHD/LxFFPTwVvZkQ9sDt+CbY+QVF5Df6TpAveKSJol/77PPbyJS04 X5Xv2iBcMKiKXlE7sdOfloN5UyS7wzw0TEaR0DnF9q0tVukPKTbZu+DsrUdlKAvk0Ekg AckSebXkX8VjmY4LEM3A8QgvIWkKz1yBHqZf0XPumAh6Dg1Ci8+HrN1UJmZisxvidoD6 UUtA== X-Gm-Message-State: AOJu0YxGNM+38Lt8VADH68Ba8RY7p2YlMKsk0O78+oR4mULvHm0Vmncj Sf1Cg0bcbxrZNJMlmdRMUlSjkydrXDEUxtLBFuJrompDgKogzXjsiYi3SEZYnjOfHSk4trt1PGG GOY4L/jwIdRHGI/L0frI6PwW4KG1RKA== X-Google-Smtp-Source: AGHT+IHTOhY2G3JxLOMdaPBWX1DILMcO7Pfhqrenv/SriRjmaE0wTfTlmbIK6Z1vDaAv2DQkK18bCgYulrpWnYeSV9M= X-Received: by 2002:a05:690c:60c1:b0:6db:db7b:891c with SMTP id 00721157ae682-6ee55bf06a3mr165775347b3.14.1732017427767; Tue, 19 Nov 2024 03:57:07 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <68eba37e-1bfe-4509-af41-112bb196415c@app.fastmail.com> In-Reply-To: <68eba37e-1bfe-4509-af41-112bb196415c@app.fastmail.com> Date: Tue, 19 Nov 2024 12:56:56 +0100 Message-ID: Subject: Re: [PHP-DEV] RFC: Records To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000086ed18062742bb7c" From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --00000000000086ed18062742bb7c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, niedz., 17 lis 2024 o 08:24 Larry Garfield napisa=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 all > the time.) > What visibility would you expect for inline constructor properties in service classes? For records it is clearly a public fields declaration, while for service classes I'd expect private|protected - adding visibility increases the boilerplate back to normal classes. > The alternate creation syntax... OK, this one I can't really see a benefi= t > to, and Ilija already noted it may cause conflicts. > I agree, personally I'd see "new" keyword used like for normal classes still feasible. > I would far prefer assembling record-ish behavior myself, using the > smaller parts above. Eg: > > final readonly data class Point(int $x, int $y); > > "final" prevents extension. "readonly" makes it immutable. "data" gives > it value-passing semantics. Any class can use an inline constructor. > "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 easi= er > 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" keyword without having "final"? Although I like the "data" keyword very much. Kind regards, -- Micha=C5=82 Marcin Brzuchalski --00000000000086ed18062742bb7c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Larry,

niedz., 17 lis 2024 o 08:24=C2= =A0Larry Garfield <larry@garfi= eldtech.com> napisa=C5=82(a):
...
I can see the benefit of an inline constructor.=C2=A0 Kotlin has something = similar.=C2=A0 But I can see the benefit of it for all classes, even servic= e classes, not just records.=C2=A0 (In Kotlin, it's used for service cl= asses all the time.)

What visibility wo= uld you expect for inline constructor properties in service classes?
<= div>For records it is clearly a public fields declaration, while for servic= e classes I'd expect private|protected - adding visibility increases th= e boilerplate back to normal classes.
=C2=A0
The alternate creation syntax... OK, this one I can't really see a bene= fit to, and Ilija already noted it may cause conflicts.

I agree, personally I'd see "new"=C2=A0keywo= rd used like for normal classes still feasible.
=C2=A0
I would far prefer assembling record-ish behavior myself, using the smaller= parts above.=C2=A0 Eg:

final readonly data class Point(int $x, int $y);

"final" prevents extension.=C2=A0 "readonly" makes it i= mmutable.=C2=A0 "data" gives it value-passing semantics.=C2=A0 An= y class can use an inline constructor.=C2=A0 "with" is designed t= o work automatically on all objects.=C2=A0 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 conc= erns, questions like why would you use "data" keyword without hav= ing "final"?
Although I like the "data" keywo= rd very much.=C2=A0

Kind regards,
--
Micha=C5=82 Marcin Brzuchalski
--00000000000086ed18062742bb7c--