-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HashMap toArray() does not use $preserveKeys by default #22
Comments
I am actually unsure what to do about keys in general. There is a ticket open about preserving keys on I'd like to hear more arguments on both sides of this issue. |
Just thinking out loud here, I would think this is difficult to get right, due to the manner in which PHP handles arrays. Generally speaking, I consider the following:
For instance, a <?php
$dictionary->getElementAt(7); // yields the element at index 7 in the underlying collection
$dictionary->getElement($key); // performs an implementation specific lookup for $key Depending on the implementation, the order of which the elements are stored in the underlying collection may not be relevant, and Why does this translate to the problem at hand? I would argue that the keys generated from <?php
var_dump($hashMap->toArray()); Would possibly yield:
|
I'm afraid I don't really see the big picture, but I would rather work with a easily usable and readable API than work with a flawless theoretical design. I do understand the rationalization behind your last example, but without extensive syntactic sugar (not really doable in php), I don't even want to imaging working with such Then again I might be misusing this library. What I understand any STL should do is create semantic data types which when used form more readable code. Also, hinting is somewhat compelling reason: having a standard php array used as hash map does not limit use of e.g. 3rd party libraries always take raw array as argument, which is reasonable. I want to work with abstract data structures in my own code though, so what I would run into is for example a |
Believe me, I am no authority on flawless theoretical design (or even design in general) My comment was more of an on-topic stream of conscious ;-) Ultimately, due to the fact that Ardent hasn't (yet) become a dependency to many libraries, the likelihood is that you'll have to map the type into a native array of . Hopefully, libraries like (but preferably only) Ardent will become ubiquitous, and |
I think the reason we are in this state of things is because in PHP arrays always have keys and more critically here, so do I am still undecided on what to do, but I have some changes that will be coming tomorrow (yay BC Break Thursday!) that will cause |
It's been a while and I like the idea of preserving keys whenever possible. The reason is that if you strip keys you can't get them back. If you don't want the keys you can always strip them. I should review all the structures and algorithms to do this whenever possible. |
The one function that comes to mind for me on this topic from PHP core is Only in cases where I use it and where I know the keys are standing in the way I can switch it to off by setting it. I think this follows the same principle as outlined by @morrisonlevi in the last comment. So perhaps this is already fixed by switching to such a default? |
While
$preserveKeys = FALSE
is default everywhere, wouldn't it be better to break the consistency for Maps? Or better yet, preserve keys by default? It feels like it should be more general use case.From the user standpoint, I would rather use self describing
$map->toArray()
. The additional boolean argument is not self explanatory (on first sight, without checking the function declaration). And while$map->toArray($withKeys = TRUE);
is readable, it does not really cut the mustard as it's waaaay too long.The text was updated successfully, but these errors were encountered: