I’ve had this idea for a fun weekend project for a while: generate the WP-CLI manual concurrently, instead of one page at a time.
All I needed was the right programming language 1. Since I’ve heard good things about Go, I decided to give it a try. I took the Go Tour and then just started hacking.
A WP-CLI manual page is generated by:
- collecting data from inline PHP docComents
- reading a markdown file with additional documentation
- running everything through
ronn
to generate the finalROFF
output
At first, I tried to do all these steps in Go, but soon discovered that it would duplicate too much code. Eventually, I settled on just letting WP-CLI generate each page, using the existing logic.
So, I ended up with less than 100 lines of Go code:
I’ve tried on several occasions to use threads in various programming languages, but never felt I really mastered them. By contrast, I was able to grok goroutines and channels in a weekend; they just made sense.
In general, the Go documentation is the best I’ve seen so far. For instance, when you look up a function from the standard library, besides a helpful example, there’s also a link to its source code.
I also like go fmt
, which takes care of formatting your code; no more worrying about spaces vs. tabs etc.
Even if it yielded a modest 23% speedup (from 17 seconds down to 13 seconds to compile all the pages), it was a worthwhile experiment.
-
PHP doesn’t have any support for concurrency. ↩