zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.33k stars 284 forks source link

Make ID and URI type aliases #173

Open blueforesticarus opened 2 years ago

blueforesticarus commented 2 years ago

Because ID and URI are not type aliases, you cannot automatically convert a []string of spotify ids into a []spotify.ID when calling functions like GetAlbums.

If they were defined as aliases, the type conversion would be automatic. see here

zmb3 commented 2 years ago

Yes, but at that point why have a type at all? Might as well just accept strings in that case.

The original motivation behind a distinct type for Spotify IDs is they are a specifically formatted string and it allows the type system to help distinguish where these IDs are required.

blueforesticarus commented 2 years ago

yes, but you can pass a string implicitly to a function demanding a spotify.ID it only doesn't work for functions demanding a slice. It is inconsistant behavior. (to be fair, the inconsistancy is in the golang spec )

there is nothing here that protects you from passing badly formated strings the type IS a slice of string, it should accept a slice of string

blueforesticarus commented 2 years ago

it also means I have to write functions like:

func blah(Ids []string) []spotify.ID {
    return *(*[]spotify.ID)(unsafe.Pointer(&Ids))
}

func blarg(Ids []spotify.ID) []string {
    return *(*[]string)(unsafe.Pointer(&Ids))
}

Just to be able to use the function.