Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107090 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46603 invoked from network); 14 Sep 2019 11:46:03 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 14 Sep 2019 11:46:03 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 38F962D2031 for ; Sat, 14 Sep 2019 02:22:23 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,HTML_MESSAGE, KHOP_HELO_FCRDNS,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 188.165.0.0/16 X-Spam-Virus: No Received: from poczta.brzuchalski.com (ns220893.ip-188-165-245.eu [188.165.245.118]) by php-smtp3.php.net (Postfix) with ESMTP for ; Sat, 14 Sep 2019 02:22:21 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 05CBF2984236 for ; Sat, 14 Sep 2019 11:21:50 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DOkF1WCHxLhY for ; Sat, 14 Sep 2019 11:21:46 +0200 (CEST) Received: from mail-ot1-f45.google.com (unknown [209.85.210.45]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 5ED262984233 for ; Sat, 14 Sep 2019 11:21:46 +0200 (CEST) Received: by mail-ot1-f45.google.com with SMTP id b2so31582565otq.10 for ; Sat, 14 Sep 2019 02:21:46 -0700 (PDT) X-Gm-Message-State: APjAAAWMBXeSXhyFEuuFyrD46DkPUto5sWegWDY8X5ZSW2nKBrWHK2pa Q3igbYS0t/IkheZ7DFnivPevT2Vg/bNzNjMrbcU= X-Google-Smtp-Source: APXvYqx88YhttczDu8AkzHel5aFwQ7nbElmJl2TbRoT+YdqT0BWuJGc1aSzRHuq4CJsJTA2od57KZTU+SZs20Fkl4s8= X-Received: by 2002:a05:6830:1597:: with SMTP id i23mr2670508otr.182.1568452905103; Sat, 14 Sep 2019 02:21:45 -0700 (PDT) MIME-Version: 1.0 References: <358fd32a-4d61-7947-293b-8a309e4e31ff@php.net> In-Reply-To: <358fd32a-4d61-7947-293b-8a309e4e31ff@php.net> Date: Sat, 14 Sep 2019 11:21:32 +0200 X-Gmail-Original-Message-ID: Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="00000000000041795105927fe63a" X-Envelope-From: Subject: Re: [PHP-DEV] [RFC] Object Initializer From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --00000000000041795105927fe63a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Sebastian, sob., 14 wrz 2019 o 11:05 Sebastian Bergmann napisa=C5= =82(a): > Am 13.09.2019 um 15:23 schrieb Matthew Brown: > > Though this is truly a stylistic complaint, I think it will lead to > > harder-to-analyse code. > > Fully agreed, and not just harder-to-analyse for a static analysis tool > but also for humans that read the code. -1 from me. > > Could you explain why additional noise caused by constantly repeating instance variable name and arrow in front of property name and assignment part is easier to read? Just wondering why you see object initializer as harder to read which I've view as easier to read. Example - easy to read: function createCustomerDTO(): Customer { $customer =3D new Customer(); $customer->id =3D Uuid::uuid4; $customer->name =3D "John Doe"; $customer->address =3D "Customer Street 16"; $customer->city =3D "London"; $customer->country =3D "GB"; $customer->phoneNumber =3D PhoneNumber::fromString("+1555 010 020"); $customer->birthDate =3D new DateTimeImmutable("1983-01-01"); $customer->email =3D Email::fromString("john.doe@example.com"); return $customer; } Example - hard to read: Why? function createCustomerDTO(): Customer { return new Customer { id =3D Uuid::uuid4, name =3D "John Doe", address =3D "Customer Street 16", city =3D "London", country =3D "GB", phoneNumber =3D PhoneNumber::fromString("+1555 010 020"), birthDate =3D new DateTimeImmutable("1983-01-01"), email =3D Email::fromString("john.doe@example.com"), }; } Thanks in advance, Micha=C5=82 Brzuchalski --00000000000041795105927fe63a--