On Tue, Apr 21, 2020 at 10:00 PM Matthew Brown <matthewmatt...@gmail.com> wrote:
> Why "list" and not "vec" or similar? "list" is also a reserved word – I'm > imagining that you'd construct a list like > > $l = list["a", "b", "c"]; > "List" usually means linked list, "vector" would be much clearer and consistent with many other languages > I imagine such a "list" type would be a subtype of "array" – everywhere > that array was accepted, a list would be also, and it would have the same > copy-on-write behaviour. > > If people are interested in having that type, there's a question of what to > do with > > $some_list["a"] = 5; > > Would you convert the $some_list to an array, or throw an exception? > Converting to an array would seem the more PHP-like thing to do. > > Similarly, the behaviour of > > $some_list[$key_out_of_current_range] = 5 > > would be a matter of debate too – would that turn $some_list into an array, > or would it fill up any preceding entries in the array with null? > I personally would prefer as little implicit magic as possible. Just throw exceptions instead of allowing people to accidentally shoot themselves on the foot. What other questions are there? Is a "list" type even a good fit for PHP, > given most of its users seem pretty content with the current > swiss-army-knife array type? If we're to dream about some bright distant future of data structures, my dream would be to have a set of structures that make their big O behavior clear, à la C++ STL or many other languages' standard libraries. Some of them are already present in SPL, but notably not what you're proposing. Additionally, it would be wonderful to have generic versions, e.g. List<int> would not just accept only ints, but would store them internally as zend_long, avoiding the overhead of zvals. > -- Best regards, Max Semenik