user-documentation
user-documentation copied to clipboard
Document how to fix varray/darray warnings
As one example, unset($varray[$x]) raises a promotion-to-darray warning, and is generally a bad idea.
We should document:
- vec\filter for the most common correct usage of this
vec\take,vec\dropfor when the keys don't matter, filter is wrong- the question 'you have
container[0 => 'a', 1 => 'b', 2 => 'c']- for your use case, do you expect deleting key 1 to give youcontainer[0 => 'a', 2 => 'c'], orcontainer[0 => 'a', 1 => 'c']?- if keys 0 and 1, Vec\concat(Vec\take, Vec\drop) when for some reason (?) we actually do want to remove an item in the middle without using vec\filter
- if keys 0 and 2:
- reinforce that varray and darray are describing guesses at the correct type; if you need to preserve keys, it's likely that the guess is wrong, and the correct fix is to replace the varray type with a darray
- replacing varray with a darray is a safe change at runtime: they're the same, except in which behaviors warn
- if the keys are data - for example, timestamps, dates, IDs, etc:varray was wrong, darray is correct. varray is only for containers where keys 0..(count - 1) are acceptable. Treat as the 'keys 0 and 2' case above
I've gone in to a lot of detail on unset($varray[$x]) here; similar is probably needed for other warnings.