Skip to content
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

Make ID and URI type aliases #173

Open
blueforesticarus opened this issue Oct 17, 2021 · 3 comments
Open

Make ID and URI type aliases #173

blueforesticarus opened this issue Oct 17, 2021 · 3 comments

Comments

@blueforesticarus
Copy link

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
Copy link
Owner

zmb3 commented Oct 17, 2021

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
Copy link
Author

blueforesticarus commented Oct 17, 2021

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
Copy link
Author

blueforesticarus commented Oct 17, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants