-
Notifications
You must be signed in to change notification settings - Fork 200
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
Go Generation | list<tuple<string,...>> -> map[string]... #605
Comments
I imagine this would encounter similar obstacles; if you pass a Could you say more about your use cases? A common pattern in wit is that something which one might use a dictionary for can often be a |
Thanks for the feedback @sunfishcode!! I agree with you that the As far as uniqueness/order goes, I know that maps in go don't promise order anyway, and keys are always unique. But I don't know how that transfers across languages...meaning, if we were to do this change, would a As far as my use-case goes, its more around preserving (where possible) idiomatic go the in wasi ecosystem. For example, currently, when I want a simple type DerpTypesTuple2StringStringT struct {
F0 string // key
F1 string // value
}
type DerpTypesIface struct {
Values []DerpTypesTuple2StringStringT
} which just feels really clunky, but ultimately can do the same thing. |
Zhou just pointed out to me that I missed your point that That said, my biggest concern is preserving idiomatic go as much as possible and I think maps are really important to the language so it would be great to figure out how to get them in there |
I'd like to explore one level deeper: could you describe what kinds of things you most often use For example, in some languages, dictionaries are a common way to implement a kind of named function parameters, like |
Config property bags where the fields and types are not known ahead of time are the prime example. |
Bailey saves me. That link she shared is my exact example. In that smithy file (of which I am in the middle of converting to wit), there are 3 types that are I am also thinking about things like http-headers which we would traditionally represent as a A third example that comes to mind is around JSON marshaling/unmarshaling. A |
@jordan-rash For HTTP headers, the approach taken in wasi-http is to define (what will be) a new resource, with a As you say, For @ricochet Looking at just that file, if I were asked to implement that interface, I wouldn't know what kinds of values I might get passed. As a user, wouldn't know what kinds of values I could pass. Is there some additional documentation for that interface somewhere? More broadly, in some systems, changing APIs is hard, because of backwards compatibility, and because there can be a lot of things to update, and in these kinds of systems, dictionaries are often considered essential, providing the flexibility to add fields or arguments to APIs without having to change the actual APIs. However, with interface subtyping (once it's implemented), if an implementor wants to add configuration knobs, they'll be able to add new Even more broadly, none of these is or will be the answer all of the time. There are a lot of different use cases out there. I'm aiming to discuss the options and give some context. |
You're essentially looking at a piece of middleware. It doesn't define the upstream API and this is an adapter for things like serialization. The other smithy files in the repo are examples of concrete values that could be passed in. I'm unsure if subtyping could work for this but maybe a resources implementation similar to http headers might be the best fit. |
I could be misunderstanding how this works, but if a resource requires an implementor to implement the I think the use case that I want support for that I don't see represented is the "property bag", which is typically a map/dictionary from string -> string. Despite our best efforts in application development, there are times when we need to be able to accept an arbitrary bundle of keyed data. Sometimes people use this to help with backwards compatibility, and other times it's necessary for information exchange between disparate systems. An ordered list of tuples isn't what I need to satisfy the above use case. Even HTTP headers don't require being ordered by key, we just need a set of the header keys that point to the values. A code generator shouldn't make the assumption that the use of |
I've created an issue to discuss various places we can improve the developer experience of generated Go bindings at #612 . I am linking this issue to it. |
Per the discussion here, it appears that a
list<tuple<string,...>>
is the wit equivalent of a python dictionary or more specifically for my use case, a go map.If wit isn't going to bring in a new type for dictionaries/maps, I think it would be good to have the code generation output a
map[string]...
whenlist<tuple<string,...>>
is parsed.Thanks team!!
CC: @Mossaka
The text was updated successfully, but these errors were encountered: