3 ms·
Great article - I particularly enjoyed the discussion of the relative distributions of different types of loops in the Go standard libraries. Having said that,
by sanderjd 13y ago
Great article - I particularly enjoyed the discussion of the relative distributions of different types of loops in the Go standard libraries.
Having said that, I thought the Go `readLine` using channels example was strange. The goroutine that provides lines to the channel actually still needs to loop over the lines, and in fact includes a DRY version of the loop in question:
for {
line, ok := file.readLine()
if !ok { break }
// ...
}
This is not to say that using an unguarded loop with a break is necessarily the best way to do this, but it seems to be the simplest DRY way to do this. I think he just wanted an excuse to demonstrate `range` with a channel.
- lazyjones 13y agoIndeed, further down in the comments (on the article) one of the Go team members pointed this out and the author just called this solution "measurably worse" without any factual basis. It's a pity that so many seemingly technical articles are littered with bias and unfounded opinions these days...