1

感觉引入了 chan 后, go 测序的阅读不是那么线性

 2 years ago
source link: https://www.v2ex.com/t/805154
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Go

感觉引入了 chan 后, go 测序的阅读不是那么线性

  matrix67 · 1 天前 · 2136 次点击

这个不一定对,只是我的一个感觉。

举个例子,https://github.com/rissw/not_yet_hit_the_wall/blob/main/03-blockread-concurrent/blockread-concurrent.go 这个作者使用并行的方式去统计大文件里面的行数,速度的确很快,几乎和 wc -l 差不多。

但是理解起来真是费劲,比 00-readfile 串行读取统计难度高许多。(但是也快很多,几十倍吧)

后来我一边阅读一边画图才理顺了。感觉 go 的程序需要配个图理解一下啊。

blockread.png

(画图的时候把变量名也重构了一下更符合自己的理解,可能和源程序的命名稍有不同,大致结构是一样的)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK