Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107824 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70608 invoked from network); 18 Nov 2019 21:16:50 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Nov 2019 21:16:50 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6B0A12D19B2 for ; Mon, 18 Nov 2019 11:09:32 -0800 (PST) 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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (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, 18 Nov 2019 11:09:31 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id 1so20073327iou.4 for ; Mon, 18 Nov 2019 11:09:31 -0800 (PST) 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=YmcZm8DRYOlOz1E9YlFO1R04Fh8QSgjlp3vkfu5DM6w=; b=gcxoZ6LWcHbyYLA/sBKgus6DHLVUe2GDOcKo6MXw2OqjyeMa9FtDFzwZvUHrx5grnL vYXWe7MIEMA0SZgYf3qL0gjOPdI2mMZCAKTlJ3JX48gzuEUW70iSIWJu5sqVBiC3ceJ+ QFUkJ6cCJOdxCmBH0qNi7ui/0SqJcSUB3J5HTQJITHakV73SEB4x1ep0PnG/FjWEI9ue 7mVaHLZJBYWgGMZQ7PFn1tF3lXShI7SIVzQ89YqF84NARfXKCDgbg0P/h9I4FB214wzY X5EkGxbpE2QrhqkCBHjeJfiI6wujExONNDUb+j2JZH7OId0uH7+XqgXxgJHuwI7W59W9 angA== 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=YmcZm8DRYOlOz1E9YlFO1R04Fh8QSgjlp3vkfu5DM6w=; b=QbTSzPIV1b3zMQfHM7SKPhJ2CNipvSEWikEFDLoHpVBzRYWTlt8NLB1kQne4Buam+C GrYjPEpi3cKIZV12Q82btzph+HWuyGfwCAt0pYngxukvBfJHTQP/WIWLPRqROUK9sUFU OpUFlnG6PAVCRoXa+kQyfw1d9c7Ng6NB+9f7Pt6OUkphxi0PFxYu8811Q46Lxz3zHM1G n9m+rO/7ZsozPZc3p5hoe0EuP+a5irmNMNf7pc47zoGSWSoodV5EPsmDKfXpReefRGJU 3+MtaA5Mq3ZvuJQ4bMv4z57DRC353DbVpM9wEuLhcjOHaeGfpZ8MigZaPGR1p9mRODSX hCJw== X-Gm-Message-State: APjAAAWmG9Sz34rBK/nQ0NuwcpGoLZMiDaxcvQhuC/8EnW2EHEhUg5ap FAbtG5ErNFkN5wO4tYlANnho9LX4OkS336n62+eUOSLA X-Google-Smtp-Source: APXvYqyGzswgt/yuUWbiyNGoDq5CjDFX4BywYg17Jh7aTcd5jhJPz0IsvZ9B1v36SOv5klCkB06jdYyGwT1UrS763Io= X-Received: by 2002:a6b:3b54:: with SMTP id i81mr10105989ioa.206.1574104170697; Mon, 18 Nov 2019 11:09:30 -0800 (PST) MIME-Version: 1.0 References: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> <08de5448-3c5a-ad32-555e-b8f9579c1337@aimeos.com> <7b527bbb-47e3-9b24-8766-c15e6334c78a@gmail.com> <1BF6C8EC-6DF1-4481-94B2-3A6E7D1312BE@newclarity.net> In-Reply-To: Date: Mon, 18 Nov 2019 19:09:19 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000ef1a260597a3afb7" X-Envelope-From: Subject: Re: [PHP-DEV] Concept: "arrayable" pseudo type and \Arrayable interface From: rowan.collins@gmail.com (Rowan Tommins) --000000000000ef1a260597a3afb7 Content-Type: text/plain; charset="UTF-8" On Mon, 18 Nov 2019 at 17:55, Mike Schinkel wrote: > > Yes, a team lead could require an interface be used for consistency across > a team, which is fine, but it is not consistent across unrelated projects. > Having worked with GoLang for a while where interfaces are not required to > be explicitly named by classes that implement them I have learned that > having consistency across unrelated projects can result in some > surprisingly serendipitous reuse scenarios. > > That's actually precisely why I *don't* like generic names like __toArray(). How do I know looking at it whether this particular method will give me something suitable for passing to a Mustache template, or just a list of IDs used in some cross-referencing algorithm? The only thing I know from the name is "it returns an array". > Forgive me for saying, but that argument is bordering on reductio > ad absurdum. We are talking about a magic method for converting to a > *built-in *data type. > > ... > That said, I could see a value in having __toInt(), __toFloat(), and > __toBool() as having them would allow us to represent scalar data types > in classes. That could be extremely useful in selected contexts. > > So given the argument there would at maximum be five (5) new magic methods > that could be added vs. the infinite methods you assert this approach would > invite. > > I didn't say it would *invite* infinite methods, I said it would only give the claimed benefits if you had a huge number of magic / "standard" methods, because you need to "standardise" every method you have in your current code base. __toBool() is perhaps a good comparison. Would you consider renaming a method called "isSuccessful()" to "__toBool()" a positive change? Because I would not. If there is a common requirement for objects to be converted to a > particular type of array, then you should pick a standard name for that > > > You assert that a developer *"should"* do it the way you believe is > correct, but what is the arbiter of *"should"* vs. *"should not"* here? > Is there some fundamental best practice that the industry has universally > embraced that I am unfamiliar with, or just your opinion? > > Are you saying that you *don't* believe consistency is a good thing? Because that's all this sentence really says: "if you have something you do a lot, you should do it in a consistent way". The justification for that can be found in the introduction to any style guide you can lay your hands on. > Absolutely agree that names need to be meaningful, which is why I want > more control, not less. > > What you are implicitly saying is that rather than allow others the option > to use __toArray() which by its nature could result in consistent use > across unrelated projects you want to deny others who value it from being > able to take advantage of it because you personally do not see value in it > and would not use it. Or did I misrepresent? > > I think you are misrepresenting slightly. I haven't actually said I want to "deny" or "block" this addition. What I have said is that I am unconvinced by the arguments being put forward in favour of it, and have tried to point out what I see as flaws in those arguments. In particular, if your claim is that it will make code more consistent across code bases, it's no use if you're the only person that adopts it. So let me rephrase from a personal objection to a prediction: I predict that people will not use this feature consistently in a way that will bring the benefits you claim for it. > So I now understand that you were proposing even less than I thought you > were proposing. I thought you were proposing that PHP would recognize and > give speaking meaning to a method called toArray() or similar. Now I > realize you were proposing even less and instead placing the burden of said > standardization on each project, guaranteeing no serendipitous reuse across > projects. :-( > > There is certainly benefit to standardising things across projects, and that's what organisations like PHP-FIG try to do. However, standardisation is more useful the more specific it is, and if the definition of "toArray" is just "it returns an array that in some way represents the object", I'm struggling to see how that would lead to useful interoperability. > But it is reasonable to expect that a class could need both an __invoke() > and a __toArray() method. > > It's also reasonable to expect that a class could need two methods that return arrays; you've already "solved" that, by splitting the methods among more classes and namespaces so they don't need unique names any more. > Also there is no guarantee that an object that implements __invoke() will > return an array whereas there should be a reasonable guarantee that if > function_exists($object,'__toArray') is true that casting to (array) > would be valid. > > Which brings us back to square one: knowing that a method returns an array isn't enough; I need to know what kind of array that is, and the thing that normally tells me that is the method's name. Regards, -- Rowan Tommins [IMSoP] --000000000000ef1a260597a3afb7--