Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71337 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11422 invoked from network); 20 Jan 2014 19:42:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2014 19:42:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.179 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.179 mail-lb0-f179.google.com Received: from [209.85.217.179] ([209.85.217.179:34391] helo=mail-lb0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/25-02192-F0C7DD25 for ; Mon, 20 Jan 2014 14:42:08 -0500 Received: by mail-lb0-f179.google.com with SMTP id l4so3630832lbv.38 for ; Mon, 20 Jan 2014 11:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=kAdhH3G8ZLXQnygvkT/+ltvxFjvcq8eVOa/MGOK+MS8=; b=BmVAUjcHvYX59eawSlsqooc1zlBeR4wsBHq9kWXfpqUEAC+JZHPsxwvzsfpa/uCcSR F6FIoxfvszvVLWLMihxKx14Uw5LSHvbB0QmQ7yUP2HvJxaoskHHG5lf3CA1cKUi6dAP4 pf7CuVgFySvDhCOo3H4c9uRUQ4Za7Q0gvo8nFv6AzdMlQ47w6b1IqAM5bqZVdpcqYdBE BawmLdjXS51gMnCmtPdEqZUtxLsv/4OYTnYTke3riRHnyo185/0lzgJRd4Kfa7OWNHco dtVQBzbJroS14fQx/JI/4+se1OZ82IC39y08zgQiwiLDgs1PO+AT20LWOmhnMmmYFg3j wRUA== X-Received: by 10.112.78.4 with SMTP id x4mr48909lbw.81.1390246924663; Mon, 20 Jan 2014 11:42:04 -0800 (PST) Received: from nikita2206-n56vj ([217.174.184.92]) by mx.google.com with ESMTPSA id p3sm2181580lae.2.2014.01.20.11.42.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Jan 2014 11:42:03 -0800 (PST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <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> <52DCED71.3020207@pthreads.org> <006301cf15f5$22f8df60$68ea9e20$@tutteli.ch> Date: Mon, 20 Jan 2014 23:42:02 +0400 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: inefedor@gmail.com ("Nikita Nefedov") Hi Philip, On Mon, 20 Jan 2014 22:43:41 +0400, Philip Sturgeon wrote: > Generics > ------------- > > As Joe has pointed out, this RFC has nothing to do with generics. They > are a whole different kettle of fish. > > 1. Rasums hates them > > http://comments.gmane.org/gmane.comp.php.devel/76495 This is Rasmus's concern, I don't think it should be a reason for denying it. I'm sorry for a little rough words but your know PHP is now open-source and all that stuff... > 2. I hear a lot of people saying "PHP is turning into Java" every time > anything vaguely OOP happens (which is frustrating, and... factually > inaccurate) but adding generics would be INCREDIBLY Java-esque. > > http://en.wikipedia.org/wiki/Generics_in_Java Why do you give a f*ck? I mean, maybe it's something Java-ish, but so what? It's useful, it will make our lives (as a PHP developers) a little better. So why not? I, for one, have a project right now, where we have a ton of typed collections. And generics is the thing that would made our lives easier. I believe we are not the only ones... If don't like the syntax, or you don't like the idea, you can just not use it. > Those who are interested in it should discuss it, but I do not know > why we are talking about them here. Maybe a new RFC and a new thread > for Generics can occur, but they are not alternatives to the same > solution. We are talking about it here (at least I'm thinking about it) because arrayof is pretty exotic feature. A lot of people here are proposing to add typed array structure, but it will differ from arrayof... While with arrayof you can typehint for interface, a typed-array can only hold records of given class. So the semantics are differ. But with generics you can achieve the same goal as with arrayof (you can typehint for interface. I know Java enforces you to pass an end-class, but I don't see a reason to make it as in Java. I would make it possible to pass in generic binding an interface, it's pretty straightforward as I see, OOP-ish and goes along with SOLID) but without the overhead of checking everytime you get an array of something... > "Type-checking is not PHP" > -------------------------------------- > > PHP is a loosely typed language. It allows arrays to contain a mixture > of content. It is very vague. GREAT. > > Type-hints are lovely for when you do not want to be vague. > > A plain-old function declaration: > > 1. "Give me a bag of stuff, and I'll try using everything like it's a > spanner, but it could be a banana and... well I guess my wing-nuts > will get covered in banana gunk, but whatever, YAY WEAK TYPING." > > or > > 2. "Give me a bag of stuff and I'll fish around in there trying to > find spanners, and ignore everything else" > > This RFC optionally allows developers to say: > > 3. "Give me a bag of spanners, and break if they put anything else in > there." > > Optional, opt-in, simple, logical, useful. PHP is a multi-paradigm language. It won't enforce you to use some concrete paradigm, even if we do implement generics... > Syntax > --------- > > There have been a lot of people suggesting various types of syntax. As > Joe said, using generics syntax for not generics would be a travesty, > and an overcomplication of what should be a simple feature. > > For those who hate OOP, array of would be a lovely way to ask for an > array of callables. Trying to make generics happen is a great way to > force not only new syntax, but a brand new OOP paradigm that will be > new for EVERYONE, so ignoring that syntax and letting our functional > and OOP folks have a nice thing shouldn't be considered a negative. I would love to get generics as long as typed arrays. And when I say typed arrays I mean array which can hold only the elements of said class (not an interface). It's not just semantics, it's also optimization that can be done when you know that array will hold only elements of the said type. (You know how much memory element will take. It'll make a room for possible optimizations) Sorry for some sharp words...