3 ms·
>Imagine your documentation says: this functions returns a List of items. You can still returns a CopyOnWriteArrayList. I don't write in Go so I don't know how
by clusmore 10y ago
>Imagine your documentation says: this functions returns a List of items. You can still returns a CopyOnWriteArrayList.
I don't write in Go so I don't know how the Go community feels about this, but I don't like the idea of a mismatch between documentation and implementation. A non-trivial number of people will only read the documentation when something goes wrong. If the function is defined as returning a CopyOnWriteArrayList they will assume that's the return type. If they bother to read the documentation, the mismatch will be confusing and the more obvious inference will be that the documentation is simply out of date.
>you would remove the ability for the next developer, which has more information than you, to rely on it
Yes, this is exactly what I _want_ to do. If the fact that I produce a specialised type rather than an interface is purely incidental, then I don't _want_ people to rely on it -- I won't be able to change my mind later. "Don't promise what you can't deliver." If it's not incidental, then of course be as precise as you feel is appropriate.
Also I'll concede that this opinion is mostly for library writing, less so for internal usage where the caller is you/your team anyway.