Should I mostly use io.Writer instead of []byte in signatures?

I recently watched the following video by Steve Francia which promotes widely embracing the io.Writer and io.Reader interfaces. See 6:15 onward.

I understand that there might be cases when you explicitly want to not allow anything other than []byte into your function.

I understand that the point of an interface is to make the program more flexible. But would you ever use the io.Writer interface in a signature even when at the time of writing the method you have no immediate other functionality in mind which would require satisfying the io.Writer?

What is your take on how to decide whether to use one or the other?

You can always add Write method afterwards, so you can safely use []byte too. However, it’s better to use Write if it really writes into []byte.

1 Like

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