Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107177 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29877 invoked from network); 16 Sep 2019 21:52:01 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Sep 2019 21:52:01 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 74FD82C0796 for ; Mon, 16 Sep 2019 12:28:54 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE 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-yw1-xc35.google.com (mail-yw1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (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 ; Mon, 16 Sep 2019 12:28:53 -0700 (PDT) Received: by mail-yw1-xc35.google.com with SMTP id 201so267208ywn.13 for ; Mon, 16 Sep 2019 12:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=blusMaBLtn05y4lWEfqRKlOnYqWqpJ9MDCBI6STupOo=; b=DA1578RtnMzVxYwhv27juk94q00TOiYSleVbkPN+iN6cmHlE5uEPMgU+H3UTfaJF5q PCKWBo6QvM9ESVGpJ2TgWkhQ6efE3Xye4yQ39S//ndH3NlIZXwZgsdznjj33rLGOyZjg oJJ2M+gVnAK5O8gM7gtCjalnhZ9eKjij3eFpWPujYKgV8CVjm97w3KpE8LUG3+atlDzy t7IIVXo/9tOw7cVT3JDRRDf0VdUdyzVaamHi4Owh8pz3suJxiFj9WB9GkGDBqevVi2xd 4ZLx9VR24o9AobK96dhMDeOYZQtKLcQ7uTif36tmuth1tGAfddCwkWD2VUjE7Jfn8Q3r LFKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=blusMaBLtn05y4lWEfqRKlOnYqWqpJ9MDCBI6STupOo=; b=pZG3h7jD5w2dTiL6LLnAqbvvqLcBkxT7OinGvM8jgMtfAsQ1YxWri/GJc7tHuTn71/ eX8/pSRIKBOZA3TmGECKXY+t4h/WMpOH0Z3L75gaHvZEVoDgLNAmxv1IZxYxK4R5yhjc M5Vu0CuNahqecFHbMSJsHG4PJgg8tmmESyD2P4Hq8MqAkiQ/2BnKBbastlXW7vrPKQNa GdAop5QyX0GYcwA1NcT/rTmAoXM2XlMgF4X9KcPDtbFNvcpGjI0rtjFvQwM+mtG3OGn2 zdMIHIXX/8dwiJhkLK6t5HXUFVyBjBn68oDP5i3QDFzrcfiOcwokYkYjl4kfOEzXM9xc aD+A== X-Gm-Message-State: APjAAAV7KNGz49lfIq/SJr/fRLE2Z6HQeiswJd9TA0KUadS5Xur3HHzc +DUOEY86Vd258N47LRZ7XNlReg== X-Google-Smtp-Source: APXvYqxX7SxNFxyTip7DgvxOvVHwj6+nOxKIHthYIgDUPdAePYHjyrNDibNJQCVnRZqbn7GzZ1iSPQ== X-Received: by 2002:a81:6cc1:: with SMTP id h184mr1145250ywc.380.1568662133527; Mon, 16 Sep 2019 12:28:53 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:f4e5:82c9:8e75:5377? ([2601:c0:c67f:e34e:f4e5:82c9:8e75:5377]) by smtp.gmail.com with ESMTPSA id z127sm8475039ywd.45.2019.09.16.12.28.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Sep 2019 12:28:52 -0700 (PDT) Message-ID: <83819928-59BF-4C02-9F97-59306EE97F90@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_3A509B20-936B-4CFD-9A9A-617FFC5EDE56" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 16 Sep 2019 15:28:52 -0400 In-Reply-To: Cc: PHP Internals List To: Rowan Tommins References: <472D3E22-18D9-4C25-8961-C1DDEF482981@newclarity.net> <58673C6E-6632-42D9-BCBF-0294A62EB001@newclarity.net> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Features related to Object Initializers From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_3A509B20-936B-4CFD-9A9A-617FFC5EDE56 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I had to snip context and split in two to get under the 30k char limit.=20= > On Sep 16, 2019, at 6:22 AM, Rowan Tommins > wrote: >=20 > Points 1 and 3 are solved by anonymous classes, which we already have. > Point 2 is a bit vague; is your point essentially "if we had nicer = syntax > for anonymous classes people would use them more"? If so, then see = next > section; if not, I'd like more clarification on what you were trying = to > illustrate with your "nested parameters" example. The primary point here was: "If we had an easier syntax for object initializers, people would be = more likely to use them instead of using arrays" Note I said "object initializers" not "anonymous classes" because the = alternative is people using arrays.=20 And that is one of reasons things I really want object initializers; so = that developers who use arrays for structured data will be more likely = to use objects instead. Myself included. > The problem with trying to make anonymous class declarations and = object > initalizers look and feel similar is that there's a lot more that can = go > into an anonymous class declaration: types, visibility, methods, = traits, > "extends" and "implements" clauses, etc.=20 Good point about anonymous class declarations. =20 Frankly though, I personally (almost?) never use anonymous classes = except for very simple ones because anonymous classes quickly because = too complex. I find it much easier to reason about named classes at the = point they need features like visibility, methods, traits, extends and = implements clauses, I see object initializers as a subset of anonymous class declarations. = IOW, if declaring (what I will call) ad-hoc objects get too complicated = then users will stop using them for the object initialization use-case. = This is premised on the fact I have usually seen less-zealous = developers take the path of least resistance and arrays have been that = path. A lot of the code I have seen has been in WordPress plugins =E2=80=94 = and some people on this list have made comments about them =E2=80=94 but = if the PHP community wants to see them become better then making it more = likely they will choose the better path will help improve them. So if we get developers using objects instead of arrays, I think are = will be more apt to recognize that they can benefit from declared named = classes and move to those instead of objects. But if they are using = arrays, I see no evidence that they will move to declared named classes. > I think that's a good reason not to think of them as related features, = unless > you can think of use cases where having variable capturing in an > anonymous class declaration would mean you would no longer want object > initializers? That question is confusing me given the context. Was there a typo/is it = worded correctly? > I'm a bit confused here whether we're talking about constructing = objects of > anonymous classes, named classes, or both. Your example showed = constructing > a defined Query object, but your comments above sound more like = they're > about using anonymous classes (as a replacement for arrays). I understand your confusion; my fault. There are so many use-cases I = have for object initializers that it is hard to stay focused on one = specific use-case. And I have yet to give an example of one my primary = use-cases given it's a coding pattern I might need to discuss first so = it would be clear why object initializers would be so helpful. I see object initializers being what beginners devs would start with, = and what advanced devs would use is very ad-hoc use-cases. As beginners = become intermediate they would start using basic named classes. And when = they became more advanced they would start using features like = visibility, traits, extends and implements. So I envision it as a continuum, that IMO would be better if object = initializers were just a simplified subset of anonymous classes rather = than being an entirely different set of syntaxes to learn. > Either way, I agree with the aim of making objects easier to = construct, I'm > just discussing the pros and cons of the various suggestions for doing = that. +1! > As before, the definition of the class itself is simpler, but I think = a > short-hand syntax for constructors would be a better compromise than a > syntax that only worked with public properties and parameterless > constructors. I think short-hand syntax for constructors would probably be a great = feature oo, but do not think of them as satisfying any more than a few = of the the use-cases for object initializers. =20 But before I can give examples, I need to know what you are thinking = re:short-hand syntax for constructors? =20 > I don't understand what you mean here. Your example showed a = QueryBuilder > class being refactored to use a Query object instead of multiple > parameters, which is something that can happen right now, no language > changes needed. The only new feature your example showed was a = different > way of constructing the Query class. This is because of trying to come up with examples that address many = different use-cases. It is hard to come up with examples for all = use-cases in one sitting. > I agree, and I never said otherwise. I do think that an important part = of > deciding whether to implement a feature is evaluating its limitations, = and > what use cases it would and wouldn't help with. >=20 > I'm not saying this feature should never happen because it doesn't = work > with interfaces, I'm just saying that is a limitation to consider. Understood. 1 of 2 ...continued=20 -Mike= --Apple-Mail=_3A509B20-936B-4CFD-9A9A-617FFC5EDE56--