To me this is the whole issue. Of course if we have knowledge outside the method declaration about what values can be left 0, then we can pass the correct ones as needed. But the interface is ambiguous about when that is acceptable, and the implementation can change without changing the interface.
According to the mail lists I've read on the subject, the correct way to implement your algorithms in Go would be for each to be a separate method. And indeed that is the only way in Go to support a fully specified interface.
In Go, when you create a new variable, it's automatically set to the null/zero value. So in this case, they would be nil.
So not the same thing with default values at all.
With this struct interface you just implement "optional" values...
In skein package:
var DefaultHash = &Args{ ... } // the default args you want
Users will call it like this: skein.New(32, &skein.DefaultHash)
Another way, better for some cases, is have methods on arguments struct, like in base32 package from stdlib http://golang.org/pkg/encoding/base32/ base32.StdEncoding.DecodeToString(...)
base32.HexEncoding.DecodeToString(...)
In most cases (but now all), there are better ways to design API than stuff them with default arguments, which make functions behave unexpectedly if you forget something.But maybe we should talk about specific cases? What are the examples of functions which need to accept default arguments? Maybe I can try to convert them into something reasonable in Go?
I exported this struct:
and then provided a function: Users can easily call it like this: I like this design a lot.Plus, with structs as arguments you can easily provide more than one default configurations. For example, if you want to personalize hash for different usages:
and use them: (Note: Args is a bad name for general usage -- I called it like this only because Skein authors call these "arguments", and "configuration" is reserved for something else.)There are a few specified usages for Skein with arguments, so to avoid making users of my library read the Skein paper, I wrote "constructors" for them:
Simple.