Re: Introducing "Array Of" RFC
| From: | Nikita Nefedov | Date: | Mon, 20 Jan 2014 19:42:02 +0000 |
| Subject: | Re: Introducing "Array Of" RFC | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-71337@lists.php.net to get a copy of this message | ||
Hi Philip,
On Mon, 20 Jan 2014 22:43:41 +0400, Philip Sturgeon <pjsturgeon@gmail.com> 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/76495This 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_JavaWhy 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...