Abu Bakar
Feb 2, 2025

Because returning a concrete type makes the code easier to understand. You can easily see what you're working with and can recognize all the available methods, helping you understand how to use the returned value. Also, this approach aligns with Go's philosophy of "Accept interfaces, return concrete types." It gives flexibility to the caller, allowing to convert concrete return type into any interface needed, while the reverse is not as straightforward. Returning interfaces can limit your code's flexibility. If you return a concrete type, you can wrap it in any interface, but returning an interface restricts the options.

--

--

Abu Bakar
Abu Bakar

Written by Abu Bakar

Polyglot Software Engineer | Building end-to-end, turnkey solutions for web | Designer who loves minimalism

Responses (1)