sort.Reverse consistent with rest of standard library?

I’m interested to hear some thoughts on whether sort.Reverse is consistent with most other implementations in the Go standard library.

On first look it seems like a slightly indulgent way to tell sort.Sort to do a reverse sort and does not read particularly nicely, i.e:

sort.Sort(sort.Reverse(sort.StringSlice(xs)))

Would this be more readable and more easily taught to beginners?

sort.ReverseSort(xs)

Do different areas of the standard library have a different implementation style due to preferences of the authors? Is there an effort made to maintain consistency across the board?

Not quite getting why you say sort.Sort(sort.Reverse(sort.StringSlice(xs))) is inconsistent and sort.ReverseSort(xs) is consistent.

Learning wise, I think reaching sort package - sort - Go Packages is already pretty good to get you started, what you’re describing seems more like a convinience function, one might argue it hides important details for new comers to understand what is happenning.

Readability wise I think that version is more readable, but it could be weird having 2 ways of doing the same thing (in the same package), that are functionally equivalent.

1 Like

Are there lots of other examples in the standard library where you would do something like sort.Sort(sort.Reverse(sort.StringSlice(xs))) to alter the behaviour of a function like sort.Sort?

I haven’t run into any so far.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.