Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109249 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22655 invoked from network); 23 Mar 2020 21:23:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Mar 2020 21:23:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0F0FB180543 for ; Mon, 23 Mar 2020 12:47:42 -0700 (PDT) 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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS 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-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) (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, 23 Mar 2020 12:47:41 -0700 (PDT) Received: by mail-ot1-f49.google.com with SMTP id e19so14727426otj.7 for ; Mon, 23 Mar 2020 12:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1jLpbnw7+NBTRJhKwjYO6MNlTtZSsge2/uXermOaAsg=; b=P+4ZP/vYwyR4zTzhaS+2MhE6mvmuUCogjs3Hzdu7WO5BDvh5uCNeQVmewPEPqK58QT 6jhJw9EJtGJi+jfR4Hmn0IbpUwhHwCZXdxt5Vc3RRnAI/2QI2lT5cYodbtqMtzL0Vw/F EDQVNwTiIIAoMvoonlisI0IM0bt7Rynlm+1kddr7KmAF3XX1BiBw66uPjzmNuPssBZ5g o35rN1nyN87l1tbuzvfkutgPdc68h+GioUEb8pb+8WZJRJ2NeZqjXQVtIM/O5E0H4pSZ oldC71u2ZDKZlFJUgXmAXXALUtyLbGPp447lfDUJ7ETwQ2jhv3upn+TbBmDAzFl59xqC cmvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1jLpbnw7+NBTRJhKwjYO6MNlTtZSsge2/uXermOaAsg=; b=jcGPDKAEbKKF5X7T9bWk8Ta+eyoLaAkjGRuDmrLczrrbbl4ZR4hI56QfBFqW5Gh1DY fHgZRXSHxF8+yiqU2CKBCX3rTIwRp/7x0PmKZeLZaDTXefkLIVXLGgXr20OIz/To1lJY BcNtpTmEKXD3MIK/W7xLwTM/U+PdfZE0VPkZhBJLqzi6ocsEjPX9ypkC2R2eU3JdC5e/ 5ZWXa2fWyR1EFpep/AwoCvOm9ftaoxzoFcw44POWsdf04B9vpgNTQjJ2NKS0AX2tVFQF nLC2QnTpyh3ZYR7JtVi5eANPzPV1T4jYaMkzwV8q31ChkjgoZIEVT9qAFzBh7Jh2ugCM 0DKA== X-Gm-Message-State: ANhLgQ1drJxamX2rJ661svvIKF5X5VtctyLPI8Qwnu/xogJqQh0P3xPT sE6i7twyxb1UiAPVJAdNAIXIreHxJZMW5S8sjds= X-Google-Smtp-Source: ADFU+vtQdDIajrmNxozaTmtNEHNf3FNeWbu21ix0bP5/DaW3n6pxLL8YubWbtekEYokqgd76zeC0nqMMQuWYRCadMv0= X-Received: by 2002:a9d:5a09:: with SMTP id v9mr18612209oth.214.1584992857559; Mon, 23 Mar 2020 12:47:37 -0700 (PDT) MIME-Version: 1.0 References: <1b781e1e-3f27-485b-ab47-5eeaf9496548@www.fastmail.com> <0af67f9d-ce2a-476f-abad-385080ce14e8@www.fastmail.com> In-Reply-To: <0af67f9d-ce2a-476f-abad-385080ce14e8@www.fastmail.com> Date: Mon, 23 Mar 2020 20:47:25 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000003f163405a18ae834" Subject: Re: [PHP-DEV] Improving PHP's Object Egonomics: A broad analysis From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --0000000000003f163405a18ae834 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, pon., 23 mar 2020 o 20:04 Larry Garfield napisa=C5=82(a): > Merging some replies together here... > > On Sun, Mar 22, 2020, at 8:36 PM, Levi Morrison via internals wrote: > > > In short: I believe our biggest potential win is to focus on 3 RFCs: > > > > > > * Constructor Promotion > > I would vote yes on this, assuming the implementation is sane. > > On Mon, Mar 23, 2020, at 12:55 AM, Micha=C5=82 Brzuchalski wrote: > > > That still doesn't resolve issue with lot of boilerplate when you deal > with > > small objects for which public readonly is enough like object-initializ= er > > could. So I'm not sure about my vote here. It does solve only one narro= w > > situation for me. > > The value here is combining constructor promotion with named parameters. > Constructor promotion itself is useful for the class implementer, but > doesn't help the caller. Named parameters helps the caller, but doesn't > really help the class implementer. The combination of both of them > together gives us something similar to the object-initializer syntax as a > net result, but with many other benefits because it's not a one-off synta= x. > > So with the two of them together, you get: > > class Point { > public function __construct({public int $x, public int $y}); > } > > Which then allows any of these construction mechanisms: > > $p1 =3D new Point(5, 7); > $p2 =3D new Point({x: 5, y: 7}); > $p3 =3D new Point({y: 7, x: 5}); > > All of which result in an object you can use the same way: > > print $p1->x . ', '. $p1->y; > > I agree it looks a little bit awkward and differs from object-initializers known from other languages, but let's say it would work somehow for this example. Now make it not 2 but 10-15 properties with real types sometimes quite long so after 3-5 of them you should break the line, then add some default values. Like a real entity which with typed properties doesn't need setters and getters. The example grows but even when breaking a line after each parameter/property still could be somehow readable. Now as we deal with Entity add some annotations or let's go hype, try with new Attributes v2 proposed by Benjamin Eberlei https://wiki.php.net/rfc/attributes_v2#userland_use-casemigrating_doctrine_= annotations_from_docblocks_to_attributes 3 for $id and for the rest at least one attribute per property. class Product { public function __construct({ <> <> <> public int $id, < true])>> public string $name, <> public string $description }); } Let's stop on 3 I think it's enough to see it's: 1. unusual to see annotations in method signature declaration 2. not readable anymore. Now if you say it shouldn't be like that and all the properties should be declared as normal properties, then the constructor is not needed to simplify the declaration but still requires a lot of boilerplate on the caller side undoubtedly. Do you still think object-initializer is pointless and useless and can be replaced with named arguments and constructor arguments promotion? Cheers, Micha=C5=82 --0000000000003f163405a18ae834--