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 LessThan, Equal and Compare accept a pointer type #20

Open
alexanderwilling opened this issue Dec 20, 2016 · 3 comments
Open

make LessThan, Equal and Compare accept a pointer type #20

alexanderwilling opened this issue Dec 20, 2016 · 3 comments

Comments

@alexanderwilling
Copy link

For usability, it would be nice if one could pass a *semver.Version to LessThan(), Equal(), and Compare(). Is there something preventing this? And why are those methods defined on a value receiver instead of a pointer receiver?

@jonboulle
Copy link
Contributor

jonboulle commented Dec 20, 2016 via email

@alexanderwilling
Copy link
Author

Because right now, I can't write for example foo.Compare(semver.New("1.2.3")). I know, I could just use foo.String() == "1.2.3". But I think it would make sense to accept whatever type the "constructor" (New()) returns, especially as it comes at no cost.

Regarding the receiver type, the link you provided also says:

Next is consistency. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used.

The go vet tool (or maybe go lint) even complains about differing receiver types.

@jonboulle
Copy link
Contributor

Because right now, I can't write for example foo.Compare(semver.New("1.2.3")). I know, I could just use foo.String() == "1.2.3".

foo.Compare(*semver.New("1.2.3")) works fine

But I think it would make sense to accept whatever type the "constructor" (New()) returns,

Fair point, although arguably the current situation is a bit more flexible (because you can dereference inline but not reference inline).

Regarding the receiver type, the link you provided also says:

hoisted by my own petard ;-). IMO the current situation is still cleaner but if you feel really really strongly about it you could put up a PR

The go vet tool (or maybe go lint) even complains about differing receiver types.

Strange, I can't seem to reproduce

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