Dictionaries.jl icon indicating copy to clipboard operation
Dictionaries.jl copied to clipboard

[Suggestion] mirror Array{Type}(undef, size) style

Open rapus95 opened this issue 5 years ago • 2 comments
trafficstars

Array: Array{Type}(undef, size)

Dictionary: Dictionary{Key,Value}(inds, undef)

what was the reason for flipping the argument order? OffsetArrays are the most obvious case as it fits into both domains.

rapus95 avatar Feb 09 '20 16:02 rapus95

Excellent question - thanks!

I have constructors of the form Dictionary(keys, values) - I feel this order makes most sense. To support values being a "scalar-like" thing I'm imagining "broadcasting" values into their places. This leaves undef as the uggly duckling, and I opted for self-consistency. (I kinda feel Base got this wrong; it would be easier to not have Varargs constructors on arrays and to reverse the order there too).

But yes, current compatibility with AbstractArray is annoying. To be fair I still haven't sorted through the dictionary construction (and factory) methods yet.


By the way, I'd generally encourange the usage of similar, as in similar(inds, T) where inds is an AbstractIndices.

andyferris avatar Jun 08 '20 23:06 andyferris

(By the way - just in case, please use HashDictionary not Dictionary for collections larger than 10, the Dictionary type is a simple array-based implementation with O(N) lookup).

andyferris avatar Jun 08 '20 23:06 andyferris