Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71296 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2880 invoked from network); 20 Jan 2014 06:21:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2014 06:21:37 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:38526] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/00-02192-070CCD25 for ; Mon, 20 Jan 2014 01:21:37 -0500 Received: from compute2.internal (compute2.nyi.mail.srv.osa [10.202.2.42]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id 930E220939 for ; Mon, 20 Jan 2014 01:21:34 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute2.internal (MEProxy); Mon, 20 Jan 2014 01:21:34 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=K9P/XgP1lRVPUn3ZJwJkwQ AOUoE=; b=SeeZ6BP5OsRYyxzDLy8Iu6lrH59MWR4EFibVMbQ8rA0g8oHfIQf6SD 9zFsmSN2P8W3UaUGzOf6WAlAj8L0M6OKxvGW/3fuGDt6gO+sbmsVBqD6ROek5b6Z WBQ+S85eHQ1FlL+/8avLp1UTubaLainI4xVQ36lZ7ruqz+4v5dzOw= X-Sasl-enc: 08j8VRWUgs+tdkh3PngaCHnntZpJJX4s3GI6TZMw961c 1390198893 Received: from [192.168.42.21] (unknown [98.206.137.135]) by mail.messagingengine.com (Postfix) with ESMTPA id 0C63F6800B1 for ; Mon, 20 Jan 2014 01:21:32 -0500 (EST) Message-ID: <52DCC067.9090603@garfieldtech.com> Date: Mon, 20 Jan 2014 00:21:27 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <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> <52DCA3E7.80602@lerdorf.com> In-Reply-To: <52DCA3E7.80602@lerdorf.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: larry@garfieldtech.com (Larry Garfield) On 01/19/2014 10:19 PM, Rasmus Lerdorf wrote: > On 1/19/14, 9:13 AM, Philip Sturgeon wrote: >> 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. > Actually variadics solves a problem that can't be solved other ways, > namely by-ref for an unknown number of arguments. There is no userspace > boilerplate code, looney or otherwise, that can do that. > > I won't argue whether the base need is great enough here. I am sure it > is to some people. I do have an issue with the idea that the right > solution is a full hash table scan on every function call. I have a > feeling that if this makes it in this is one of those features that will > be high my list for optimization/refactoring when I run across it in > code. As in, replace the per-call hash scan with a single userspace scan > that is only done once earlier in the stack. From a performance > perspective the only-done-once userspace version is extremely likely to > outperform this built-in per-call check assuming more than a trivial > amount of calls to the function in question. > > -Rasmus Which I think goes to the earlier point about it being better to do at add-time than read-time, since add-time is O(n) and read-time is O(n*m). Stepping back a bit, the underlying feature request, essentially, is "I want to ensure I have a collection of X without having to write a custom collection class every frickin' time". (Writing a FooCollection class whose add() method only accepts Foo objects is very straightforward, but generally needless boilerplate.) That can be checked at add time or read-time. I think that's an entirely valid use case in modern code, and can help lead to more self-documenting code, too. The patch in the RFC handles that with arrays as the collection, and run-time checking via type hints. My initial thought was "yes please!", but from the discussion here I can see where that's sub-optimal for performance reasons as Rasmus notes. Generics or something in SPL would allow for simpler add-time checking, which is what we probably want. However, if we did that then all of the various array functions don't work. That's hardly a new problem for PHP, of course. So how could we add "collection of just X type of things" support to PHP without running afoul of the "ArrayObject vs. Array" problem? I'm not sure, but I think this is another case where "arrays as the uber-data structure" gets in the way of more robust programming methodologies. --Larry Garfield