andyferris / Dictionaries.jl

An alternative interface for dictionaries in Julia, for improved productivity and performance
Other
278 stars 28 forks source link

FeatureRequest: consistent show #56

Closed schlichtanders closed 2 years ago

schlichtanders commented 2 years ago

Hi,

I just updated Dictionaries and a couple of my jldoctest failed right away. This itself is annoying, and inspecting it further showed that the current printing of Dictionaries is inconsistent and will probably break again in the future...

julia> using Dictionaries

julia> [dictionary([:a => 1, :b => 2])]  # new in Dictionaries v0.3.10
1-element Vector{Dictionary{Symbol, Int64}}:
 {:a = 1, :b = 2}

julia> dictionary([:a => 1, :b => 2])  # old style, still present in Dictionaries v0.3.10
2-element Dictionary{Symbol, Int64}
 :a │ 1
 :b │ 2

EDIT: It is about using = or | for separating key and value.

andyferris commented 2 years ago

Good point about the stability for doctests. These can be a pain! I don't foresee changes but if there are any I'll try to consider them breaking changes. There were also some legitimate bugs around when the short or long forms were chosen that got fixed at the same time...

Regarding the presentation, the vertical seperator in the long form was introduced to seperate the key and values into table-like columns. This formatting has, for example, been extended in TypedTables. I was hoping for something reasoably minimal but visually clear. (We also haven't use Pair a lot here).

The short form is a somewhat-serious attempt at a possibly literal notation for dictionaries and sets in Julia, that are based on the tuple/named-tuple formats and JSON-like braces, consideration of other formats like RON, etc. Here an ASCII or keyboard-accessible seperator is best, I feel. I'm not sure if anyone has any feedback on this?

@schlichtanders let me know if there is anything else to resolve here?

schlichtanders commented 2 years ago

hi. Thank you for giving insights into the details. I understand the table analogy, and the attempt to have a standard julia syntax for dictionaries. Still it is a bit surprising to have different separator characters in the one and in the other presentation. I don't care too much about the precise style, more important to me is that it is stable. I am glad to hear, that they will stay like this now.

I cannot provide more detailed feedback for the = presentation, sorry, but a big big thank you that you try to regard these string representations as stable API. Closing this now, as the consistent part of the issue is definitely solved.

andyferris commented 2 years ago

Awesome.

(Also keep in mind that this package is 0.3, so 0.4 would be considered “breaking” - for example I am currently implementing sorted collections, sort, etc so the token interface may get tweaked - and I can’t really consider the tokens stable or complete when I don’t know if they are suitable for a wide range of containers).