Deque's first (and current) version exposes the Init and New methods.
Both methods are very simple and can be replaced with custom code very easily.
Below:
Can be replaced with:
Note: Deque's zero value can also be used, but using deque's zero value instead of New have implications as New returns a pointer to the deque which makes it useful to be passed as params to other functions. Consider below.
func pushToDeque(d deque.Deque) {
d.PushBack(1)
}
func TestDeque(t *testing.T) {
var d deque.Deque
pushToDeque(d)
v, ok := d.PopFront()
fmt.Println(ok)
fmt.Println(v)
}
Output:
In other words, if deque needs to be passed around as a param, a pointer to it have to be used, so the New() method will likely be used more frequently.
Regarding the Init method,
Below:
Can be replaced with:
The Init method, like the New, makes the code look cleaner.
The biggest advantage of removing both methods is a cleaner API, one which contains only the most useful methods, so it's less likely the users will get confused on how to use deque and would have to spend less time learning how to use it.
The biggest downside of removing either methods is a breaking change, besides making using deque a bit more cumbersome. Meaning, anyone already using deque, when they upgrade to a newer version without the methods, they will be forced to update their code as explained above. This is a big inconvenience and a lot of people gets turned away from projects who keeps releasing versions with breaking changes.
The proposal is to remove both New and Init method from the public API and instruct the users to use one of its alternatives as explained above.
If you are for it, please thumbs up the proposal; if you are against, thumbs down. If you feel strongly about your opinion, please consider leaving comments.
Your opinion is really appreciated and will be considered in the final decision.