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

Public API Discussion #6

Open
montanaflynn opened this issue Oct 16, 2015 · 1 comment
Open

Public API Discussion #6

montanaflynn opened this issue Oct 16, 2015 · 1 comment

Comments

@montanaflynn
Copy link
Owner

Would love to have some discussion on the Public API. Specifically I want to know if having types with methods in addition to the functions makes sense. I think it does but maybe having two ways to do something is confusing to some. Here's what I mean by two ways of doing things:

var data = []float64{1, 2, 3, 4, 4, 5}
median, _ := stats.Median(data)
fmt.Println(median) // 3.5

var d stats.Float64Data = data
median, _ = d.Median()
fmt.Println(median) // 3.5

Please share your thoughts with me!

@meling
Copy link

meling commented Nov 16, 2017

Stubbled across this package hunting for statistics functions that operate over a slice of time.Duration, and retains the time unit in the return value. Anyway, thought I'd share my thoughts on your question about the public API.

My take is that it is best to have one way to do it, rather than many (as in the infamous Perl language). I believe this is also the Go standard library philosophy. For example, if you look at the bytes package, you will find a lot of functions that take a []byte, but none of those functions have an equivalent method based implementation. Similarly, the methods that operate on a Buffer object, are not repeated in the form of functions that take a Buffer as argument.

My suggestion would be to drop support for method invoke, and keep the function call approach.

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

No branches or pull requests

2 participants