> But I can't think of another, more gentle way to show off
> either goroutines or channels independently of each other and in an
> isolated, small example.
I think something as simple as this would suffice:
func passBack(channel chan string) {
channel <- "from a different process"
channel <- "share values across goroutines"
}
func aboutConcurrencyIntro() {
ch := make(chan string)
go passBack(ch) // put 'go' before any function call to send it off
on it's own goroutine
assert(<-ch == __string__) // coming back...
assert(<-ch == __string__) // the purpose of a channel is to...
}
> Also, how would you show off io.Reader and io.Writer? The only isolated
> ways I can think of are with bytes.Buffer but that's kind of lame as a
> showcase, although very useful in testing.
This one may be a little more challenging. I like how Rob Pike is
always saying to visualize it like Unix pipes. I think using io.Copy
to pipe something to standard out is a trivial yet easy to understand
example. But it may be hard use in the context of your koans where
everything comes down to a simple assert between two objects. Another
idea is to use os.Open which returns a Reader for a file. If you made
an object with a Write function on it that simply writes to a string,
then you could assert against the resulting string. For a bigger
challenge (I believe "A Tour of Go" did this), you could make the
student write a function the accepts a reader and a writer. The
function must read characters off the reader, apply some sort of
simple or ridiculous character filter, and write the results to the
writer.