Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63603 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21865 invoked from network); 22 Oct 2012 22:15:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2012 22:15:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.210.42 mail-da0-f42.google.com Received: from [209.85.210.42] ([209.85.210.42:41537] helo=mail-da0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AC/03-06090-B65C5805 for ; Mon, 22 Oct 2012 18:15:08 -0400 Received: by mail-da0-f42.google.com with SMTP id z17so1566326dal.29 for ; Mon, 22 Oct 2012 15:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=TXFH4XD3bom4nnNuj8790BCUkhHS7KjSZjXe5QVgKCU=; b=aJf6pUEbseSQrRFUtLv1hUV19Z47DEu+EFjp6GMPQ1KLxoi9Q3lFRRuPfCGngvy+75 pTPYqiaEDdWKqoSLMvhCxaoPyn8d5usSMJSuU+kyE4qnPvDfDBxJ0/2laVgoxWj4FTg4 azGzA6Fx4MjnLxKAY8g+RVcxi9NAqczIcLi+C9E1qjSwNu5tdLkD7BdxYebOXzCTBZLO cgMSX+b3gK4GUp3no/Fzgl5bduYg8jI2teDubV6SxgaDRR8FSrsx04Kynl4vsnO9PfsF MgcHEcGNaKUNfe8Mff3YfvQNmxyl74toWIqBYUVAZK5t5BTFgtaHD6+RawzUIOK21Chj Rc4g== Received: by 10.68.137.228 with SMTP id ql4mr34114941pbb.125.1350944103922; Mon, 22 Oct 2012 15:15:03 -0700 (PDT) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.68.144.42 with HTTP; Mon, 22 Oct 2012 15:14:43 -0700 (PDT) In-Reply-To: References: <712F4499-949C-4C6F-A142-736A1B156189@gmail.com> <5084281C.9020507@sugarcrm.com> Date: Tue, 23 Oct 2012 00:14:43 +0200 X-Google-Sender-Auth: 9IF0rMiD9ovahDtB12G-LxrxImk Message-ID: To: Anthony Ferrara Cc: Stas Malyshev , Nikita , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Generics proposal From: colder@php.net (Etienne Kneuss) Hi, On Mon, Oct 22, 2012 at 9:44 PM, Anthony Ferrara wrote: > Stas, > > On Sun, Oct 21, 2012 at 12:51 PM, Stas Malyshev wrote: > >> Hi! >> >> > Hello, list. I want to propose generics. >> >> Please no. If you need Java, you know where to find it. Java has a set >> of great tools, great books, great community. And it's completely free. >> Anybody who needs Java can just do it. I see no need to turn PHP into Java >> > > This is not about turning PHP into Java. Can we get over that old rhetoric > already? Instead of bashing proposals like this, can we discuss them, > instead of this hatred for all things strict? > > With that aside, I have mixed feelings on this. > > On the one hand, I love the functionality. The ability to have > meta-type-safety without having to pollute the environment with tons of > empty classes with nothing more than a type hint (for all collection types) > is huge. Let's not talk about type safety, there is nothing that is type-safe here. What this proposal is describing is syntactic sugar for runtime type checks (which is exactly what type hints are anyway). The arguments for and against runtime type checks are the same that they were 5 years ago: unlike other languages that support generics: PHP will have: no compiler support => no static guarantees => runtime, unnexpected errors. The argument should really be whether the cost of having that syntax in the language is less than the benefits of catching such errors "early" (early being usually one stack frame earlier, but I have no definite stats on that). > It would definitely make defensive programming much easier. > Especially if the ability was afforded to arrays as well (function > foo(array $array){})... This would require O(n) runtime tests, I would definitely not go there. > > On the other hand, the syntax leaves a lot to be desired. It's quite > confusing and really is ugly. As far as how to fix the syntax, I'm not sure. > > But I would like to voice my support for the concept... -- Etienne Kneuss http://www.colder.ch