[swift-evolution] 100% bikeshed topic: DictionaryLiteral

Hooman Mehr hooman at mac.com
Tue Jan 9 20:27:28 CST 2018


I think this type might become more useful if we find a good name for it and better document it. For example, it is a natural fit for parameter list of Chris’ callable type proposal.

Since this type accepts duplicate “keys” and does not provide key-based lookup, the first thing that deserves a rename is “Key” generic parameter. I recommend naming it “Label”.  

This type represents how a dictionary literal looks, not what it means. When we consider the look of it, a dictionary literal is an array literal where each element is labeled. 

I can’t think of a really good name, but we may be able to find a more accurate and less confusing name.

Some of the more accurate names are:

LabeledElementCollection
LabeledValueCollection
LabeledValueList
LabeledList

By the way, why this type does not conform to any of the collection protocols while duplicating a lot of collection APIs?

> On Jan 8, 2018, at 4:29 PM, Ben Cohen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> There exists in the standard library a type `DictionaryLiteral` that deserves naming re-consideration before we declare ABI Stability, because it’s confusingly misnamed, being neither a Dictionary (it doesn’t provide key-based lookup of values) nor a Literal. 
> 
> Instead, it’s just an immutable collection of key-value pairs you can create _from_ a literal.
> 
> I’m canvassing for opinions on what it ought to be called.  Some suggestions so far:
> 
> - `AssociationCollection`: Following the term of art from some other languages. Slightly obscure-sounding to developers not already familiar. Also “association” and “associative” are confusingly similar, which brings back the is-this-a-dictionary problem.
> - `KeyValueCollection`: Problematic because key-value comes up in a totally different context in Cocoa.
> - `PairCollection`: “Pair” is kinda nondescript.
> - Do nothing. It’s not so bad.
> 
> The old name can live on indefinitely via a typealias (which has no ABI consequences, so could be retired at a later date once everyone has had plenty of time to address the deprecation warnings). Removing it as not carrying its weight (and instead using `[(Key,Value)]`, which is basically what it’s a wrapper for) is probably off the table for source stability reasons.
> 
> Any further thoughts welcome.
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20180109/1971d4bc/attachment.html>


More information about the swift-evolution mailing list