Asterisk is a free, open source PBX system. It uses Voice-Over-IP (VoIP) technology to allow an enterprise to hook up its phones to a Telco.
When I was working with VoIP, my mantra was “this is more complicated than you’d think.” OK, it doesn’t roll off the tongue like “om mani padme om“, but I said it to myself and people around me a lot. Throw in support for CODECs SIP, and RTP, and you’re having one fun time!
I don’t know how often you’ve heard “we have the source code — how hard can it be to figure out?” (Hint: really, really hard.) So I was not expecting a cake walk when I needed to write a custom plug-in for Asterisk, especially when I found that although it has terrific documentation for deploying and configuration, the doc for coding against it is scant.
Even without much doc, this turned out to be one of the funnest projects ever. Asterisk is so clean, some of the best crafted C code I have seem. As complicated as VoIP and PBXes are, in Asterisk you can figure out what you need to do by looking at the code and walking through it in the debugger.
Even more impressive, and completely contrary to the norm, is that Asterisk is getting better with age. I started out working with version 10, in which I found no cruft, no evidence of expedient hacks to accommodate new features. Later, when I upgraded to Asterisk 12, I found that the code had become better.
To get into the details: the Asterisk plug-in architecture is based on callbacks. When a module registers with Asterisk, it provides a structure of function pointers. Implementing a plug-in is mainly implementing these standard functions, which take pointers to structures as arguments.
In version 10, a function would “navigate” across these structures to get the values of various fields. But in version 12, the layout of these structures is private and values are retrieved through functions.
The astounding thing to me is not that Asterisk developers would make a coding decision based on sound software engineering principles. What is astounding is that the code continues to get cleaner as more features are added.
How has this happened? Primarily, because Asterisk is maintained by Digium, a for-profit company whose offerings include consultation and professional services for Asterisk. And, because the developers at Digium evidence some of the highest standards of the software craft that I have ever seen.
Coders spend a lot more time working with existing programs and systems than writing new ones. Some we hate. But some, certainly Asterisk, are a joy. And the coders at Digium show that software entropy is not inevitable.