Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107186 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74013 invoked from network); 17 Sep 2019 12:03:07 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 17 Sep 2019 12:03:07 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6A7CE2C04D9 for ; Tue, 17 Sep 2019 02:40:14 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Tue, 17 Sep 2019 02:40:14 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id h144so5982716iof.7 for ; Tue, 17 Sep 2019 02:40:14 -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; bh=1tgWYqXUM0+uPdTUfYPia3uvwXxlY1DliFoj1NqIRIo=; b=SjJ/3SyYkQbYWxfU77lt/b8vXcaBikuA0/lkD+gDyBJlMpn/21o7xRBWwgsdkSqdmk xvpg+rLcSpEG4hzAzZkHSbUP+/a0rMy9SCgDKMrs8IHJ+GVhyxwCCsc9FA5AMsscTn72 /5sTgOd53H1Igf4L/L2YrN3gM8JEPJG0yqMvSQlCxIgzVBmm7uyiH9/JseBIx/Z4pBKe ZcXUY0JpMqqnPKNGrtlKIrjhgr+XxhEgaJCFl4lFX9ESqeSWS+N3vuhKPpceP584XO8H 0Ej8hfkE81GQ+4gbC8FPCl40MDYl31Ty51xWLzPOnAWuYpTiD4RA0d+5RsJJGqe41VYq /UnA== 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; bh=1tgWYqXUM0+uPdTUfYPia3uvwXxlY1DliFoj1NqIRIo=; b=SN0Hoq9FPqaZl+t+K6ooEj7vyfTsKSg2d730jAl/Bh3Pb2gYRvEc8kvE4Qh5YwO34q ZNkj3cdK5WKvFfej8VP0/CjMqR/v3EKby/k6PaF/6tczf0zSpn1nymI05cHahKgmC/pH aOTQTaL/iOPX5h71E2fb9E1gn04kkf9+yLtA8HJBeLxfhiuVWNrfrGvmAQ9V3bfrsEBJ pvNUF9pElKx4LJ5bZGqjNtvbT3hYuWF9wYubgf/Z1ab1QB/1Xfvm3RkB+Ad+XOv+cfpa ZP55/4gltBI4JzOH1intjWcLfoeHa6pMbDowx2ziQG7OD/oKQPN3iMwe0Z4+LDebn4r4 vmbw== X-Gm-Message-State: APjAAAVv00oYvkuz5kEpbj9oYJQ/Ny0ki1bAivuja53b7yCAZPjYqfQ8 qvm6SR00rhV+avVdC6T/5f02ADHCdreROmQmSHPWHLQS X-Google-Smtp-Source: APXvYqwmP2Za+mHY3jXBhOqdiMuhrTK9dbuyL0QDMrdCdduBmkXJA7dsKzFYpdpXy4pPwon58OpFxRJJHlO5Sbac+Hk= X-Received: by 2002:a02:6a05:: with SMTP id l5mr3319417jac.64.1568713213235; Tue, 17 Sep 2019 02:40:13 -0700 (PDT) MIME-Version: 1.0 References: <472D3E22-18D9-4C25-8961-C1DDEF482981@newclarity.net> <58673C6E-6632-42D9-BCBF-0294A62EB001@newclarity.net> <83819928-59BF-4C02-9F97-59306EE97F90@newclarity.net> <425cf402-370f-4d6f-9d9e-82a044b70c45@www.fastmail.com> In-Reply-To: Date: Tue, 17 Sep 2019 10:40:02 +0100 Message-ID: To: php internals Content-Type: multipart/alternative; boundary="000000000000d47ea20592bc8133" X-Envelope-From: Subject: Re: [PHP-DEV] Features related to Object Initializers From: rowan.collins@gmail.com (Rowan Tommins) --000000000000d47ea20592bc8133 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 17 Sep 2019 at 01:10, Mike Schinkel wrote: > But as I said before, naming is hard =E2=80=94 except for abstract exampl= es where > you can just name it "Something" :-) =E2=80=94 and developers often don't= know what > object schema they will need until they have written much of the code. So > the ability to have a syntax that supports stepwise refinement rather tha= n > starting with one and having to switch to the other makes a lot more sens= e > to me. > > Allowing developers to start with doSomething(int $a, object $options =3D > null) and then later refine the code to doSomething(int $a, > SomethingOptions $options =3D null) creates less discontinuity for develo= pment > There is a tip that I picked up somewhere that if you're struggling to name something (e.g. a function or a class), it may be because you've defined its responsibilities poorly, and it needs splitting or merging. I, too, work with a legacy codebase that makes heavy use of $params arrays, and I frequently see things like `$params =3D array_merge($product, $customer); $params['sendEmails'] =3D true;` and then a bunch of functions whose docblocks say basically "@param array $params No idea what's in this, we just pass it on somewhere else". There is no better name for the $params array because it has no particular responsibility, it's just a bag of data. So I'm unconvinced by the anonymous class -> named class refactoring path (and even more so with some of your further proposals like populating named parameters from an object), because I don't actually want to end up with a SomethingOptions object with 50 unrelated properties. What I want to end up with is a function signature like doSomething(Product $product, Customer $customer, bool $sendEmails). The step in between might look like doSomething(Product $product, array $params) or even doSomething(array $product, array $customer, bool $sendEmails) rather than doSomething(object $params). > rather than giving them only one option for anonymous class initializer, e.g. the array initializer syntax? I'm not a fan of (object)$array, or of stdClass in general, but I think the solution to that is to expand the existing "new class" syntax with a way to capture lexical variables. I understand the desire to make a new syntax that does as much as possible, but I think we have a few different combinations to achieve that: - object initializers & simple anonymous class initializers look the same; named parameters may or may not look similar; complex anonymous classes have to use a different syntax - object initializers are just constructors with named parameters; anonymous class definitions don't look similar, but support both simple and complex cases in one syntax Either way, the whole set of features isn't going to be implemented in one go, so we don't need to work out all the details, just a direction of travel. Regards, --=20 Rowan Tommins [IMSoP] --000000000000d47ea20592bc8133--