Skip to content

Comment on Ask HN: What's the most elegant piece of code you've seen?

Comments

It has been a while since I looked at it, but I was impressed by Russ Cox's implementation of channels in the LibThread library of Plan 9. All channel operations including blocking on several channels and selecting one that is ready, are described by Alt structures, which under the hood implement a simple but elegant algorithm that appears in Rob Pike's "The Implementation of Newsqueak." I feel you want to understand roughly how Go channels works, read that paper and look at LibThread's channel implementation.

A second choice would not be so much code, but an algorithm: Thompson constructions for regular expressions.

Yeah, the blocking select on multiple channels inside an infinite for { } struck me as the coolest construct in Go. It's like a little nerve centre.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.