Last month I wrote about Eric Raymond’s (ESR) work on NTPsec and his comparison of Go and Rust with a view of replacing C with one of them as an implementation language. As part of his work on that comparison, he undertook a nontrivial project in Go.
That project was to rewrite (and improve) David Wheeler’s SLOCcount program. Counting program lines may not sound like much of a challenge but it turns out to involve more than just
wc. ESR recounts his work and findings in his blog post Grappling with Go. Even if you don’t know Go, it’s interesting and worth a read. I especially liked the way he leveraged the Communicating Sequential Processes model (CSP) to handle synchronization between threads. I remember reading about CSP years ago and I even downloaded some AT&T code to play with it but I’ve never seen it used in a real application.
The project page for ESR’s SLOCcount replacement is here if you want to try it out or you can see the code at the project’s Gitlab page. Even if you’re not conversant with Go, it’s sufficiently C-like that you should be able to understand most of the program if you’re familiar with a C-like language.