Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71272 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34854 invoked from network); 19 Jan 2014 17:13:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2014 17:13:18 -0000 Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.43 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.215.43 mail-la0-f43.google.com Received: from [209.85.215.43] ([209.85.215.43:45809] helo=mail-la0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/9B-61840-CA70CD25 for ; Sun, 19 Jan 2014 12:13:18 -0500 Received: by mail-la0-f43.google.com with SMTP id er20so4909636lab.16 for ; Sun, 19 Jan 2014 09:13:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=tJPcr0j6mbWXeUue7laU3dFodY9FDc5OwIlmxDHXz7I=; b=TTgPLw72vMAkRhFd9wx6exGkRRyupgPGEUDgZi77Lzp+yFFumvZueuKbfg4vhit33P 6V+EudLdxhorc33b4ERRcSOmWwtZFguAtnsHVPzXQeUGA4n/SZ8MypfT7u+VSLHdm4v+ nNMaqKmpf+jSnZ747LLBsdsxPXgC0wDN/kAaUf6gBpi0mzMU0jWoiY/4cmkq4pMuY9Ra 8D4BgIotmNuy6nwb6lMyU5ssUQOnY15BajOqi3Z2/ijttfO/HgQ/BMB7SPn6lteL2ZyJ M2Xvj0YyRl6niQrK69PsgsbKUQBhW6vFx6GYqABTwrH+l93Vi01Yr55oK7xG36Kfi5JU fryA== MIME-Version: 1.0 X-Received: by 10.112.144.69 with SMTP id sk5mr1535834lbb.44.1390151593667; Sun, 19 Jan 2014 09:13:13 -0800 (PST) Received: by 10.114.66.44 with HTTP; Sun, 19 Jan 2014 09:13:13 -0800 (PST) In-Reply-To: References: <001301cf1227$6d082ab0$47188010$@tutteli.ch> <002d01cf1234$01e6dc60$05b49520$@tutteli.ch> <004c01cf123d$35730870$a0591950$@tutteli.ch> <52D71748.1090402@googlemail.com> <52D71FAE.8030002@ajf.me> <005001cf124f$3a40df00$aec29d00$@tutteli.ch> <20140116110127.202079vzjsj76n7b@webmail.tutteli.ch> <0B.B1.24763.139B7D25@pb1.pair.com> <002001cf12da$2bfbda90$83f38fb0$@tutteli.ch> Date: Sun, 19 Jan 2014 12:13:13 -0500 Message-ID: To: Sherif Ramadan Cc: Chris Wright , Mark Tomlin , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: pjsturgeon@gmail.com (Philip Sturgeon) On Sun, Jan 19, 2014 at 1:16 AM, Sherif Ramadan wrote: > This RFC seems to purport in the way of improvement. I feel it's more of a > variation than an improvement on the status quo. We've had a number of > these RFCs over the years. I'd be much more interested to see RFCs that > introduce an actual lacking feature into the language like the exponent > operator RFC rather than all of these OOP syntax sugar RFCs that are > cropping up by the minute. I'm not trying to bash anyone's efforts, but I > really feel that these kinds of RFCs are mostly fluff that we could easily > do without. > > To focus specifically on this RFC I find its use cases to be extremely > limiting and mildly beneficial. PHP arrays are very generalized so that a > developer could easily have an array of integers, floats, strings, and any > other primitive in the same storage unit. To limit the type hinting just to > user-defined objects and then limit it even further to a single dimension > means chopping the number of use cases down to an 8th then chopping that > number down by another fraction. The result is such a narrow use case that > it becomes almost useless in practice. > > The idea of better type hinting in PHP is not inherently a bad one. It's > just that many of the proposed implementations seem to veer off into > fragile use cases that really shouldn't require a language change. What's > worse is that the next RFC to come after it usually makes it worse as it > tries to pull the language into an equally different set of fragile use > cases. Ultimately the user just gets confused and doesn't tend to find > these limiting syntax sugars all that useful in practice. Even though they > appear interesting in theory, they're not really so great that we couldn't > do with a pure PHP implementation that doesn't require a language change. > > Having looked over the RFC and the actual patch I find that refactoring > code which relies on the function or method itself to handle type checks > (in situations where it will cause an actual broken design by contract > effect), makes the patch a worser scenario for both the developer and the > language. It doesn't actually make the code any easier to read and doesn't > make it any easier to debug. Code that already relies on PHP implemented > type checks is better off not using the new syntax. Code that uses the new > syntax tends to get trapped into too many edge cases. So I really can't see > the upside here. I'm a little stunned by this response. By no means is this RFC fluff, and simply because you do not personally see a use case does not mean that they do not exist. Currently I am working on a HTTP Message PSR, where we would like an array of instances of the HeaderValueInterface to be sent through to a method. Currently we have to type-hint against "array" and hope the user knows what they are supposed to send through with documentation. Interfaces are meant to be a contractual obligation, not guesswork. That might seem like an edge case, but this happens all the time. PyroCMS wants an array of Widgets, or ModuleDetails, or anything. Boilerplate code for these occasions is always required and its a pain in the ass having to write it every time. To me it is confusing that there is a separation in the "usefulness" between type hinting a single item, or type hinting an array of items. For the same reason I want to be certain that an argument is a Foo, I want to know if I am being given multiple Foo's. "PHP arrays are very generalized so that a developer could easily have an array of integers, floats, strings, and any other primitive in the same storage unit. To limit the type hinting just to user-defined objects and then limit it even further to a single dimension means chopping the number of use cases down to an 8th then chopping that number down by another fraction. The result is such a narrow use case that it becomes almost useless in practice." It's wonderful that PHP allows arrays to be so vague. It's truely useful sometimes. Sometimes its not and I want to know exactly what is in there, as is the right of the implementor of a function or method. When I want to know that everything is a Foo it would be great to ensure that. Again I say I am confused how this is a marginal requirement, this is incredibly standard stuff. "Ultimately the user just gets confused and doesn't tend to find these limiting syntax sugars all that useful in practice." Who is the user? The user implementing the type hint? If they want it, they will use it. If they dont want it, they wont use it. Somebody calling said function or method is going to get an error if they dont pass in the correct data, just like any other type hint. So again, there is not a lot of room for confusion there. "It doesn't actually make the code any easier to read and doesn't make it any easier to debug" I strongly disagree with this statement. Currently if a function is expecting Foo's you need to either read a DocBlock, external documentation or read the code. Seeing Foo[] let's you know that you need an array of Foo's, right there in the declaration. That is what I consider to be readable, but I understand you might say the square brackets could cause confusion to the user. I know you can't google search for "[]", but the docs would be right there on the "type-hinting documentation" so that solves that nicely. "Code that uses the new syntax tends to get trapped into too many edge cases" Not sure what you mean here. If I want a bag of spanners I know that I'm getting a bag of spanners. That does not trap me, it is a safety catch, to make sure when I put my hand in the bag it is always going to be a spanner, and I don't accidentally pull out a bear. I think mostly I would just like you to quantify some of your statements, as you seem to be saying: 1. It is only useful to people called Jeremy on a Tuesday afternoon 2. It is single-handedly responsible for the death of Steve Jobs. 3. Explosions I think its a nice logical improvement which syntactically offers a replacement for looney boilerplate code, exactly like Variadics which a LOT of people are excited about.