The Influence of Plumbing on Programming
I strive to produce concise but readable code. One of my favorite tactics - minimizing the number of local variables - usually can be achieved through minting or discovering higher-level abstractions and joining them together in a more or less declarative way.
Thus, when writing Go code, I often utilize io.Reader
and io.Writer
interfaces and the related io
machinery. A function like io.Copy(w io.Writer, r io.Reader)
can be a perfect example of such a higher-level abstraction - it's a succinct at devtime and efficient at runtime way to move some bytes from the origin r
to the destination w
.
But conciseness often comes at a price, especially in the case of I/O handling - getting a sneak peek at the data that's being passed around becomes much trickier in the code that relies on the Reader
and Writer
abstractions.
So, is there an easy way to see the data that comes out of readers or goes into writers without a significant code restructure or an introduction of temporary variables?