Lua is a deceptively simple language. Its designers have done such a good job of keeping it downwardly scalable to simple uses that it’s easy to overlook the advanced parts. One of these is its polished implementation of coroutines.
Why Coroutines Matter
The combination of coroutines, tail-call optimization, and closures means that many sophisticated control structures can be implemented in Lua pretty easily. Rather than turning functions inside-out and nesting them inside an arbitrary primary function, untangling them and giving each its own main loop often simplifies things. Allowing individual closures to suspend and resume means that backtracking, lazy streams, constraint propagation networks, and so on can be expressed cleanly. Also, asynchronous IO can be coordinated with functions like
luasocket.select scheduling coroutines; each can still be read linearly, and there’s no need to CPS-transform everything by hand with callbacks.
Read more on A Field Guide to Lua Coroutines…
graphviz is a great tool for creating quick diagrams. While it does not have a particularly polished WYSIWYG editor such as omnigraffle, it can automatically create diagrams from its simple markup language, DOT. After reading in the DOT markup, it uses various layout algorithms to automatically arrange the diagram. The DOT language is pretty flexible in its formatting and quite easy to generate from other programs.
The main installation includes a couple of standalone programs, such as
neato. I’ve mostly used
dot, which creates directed graphs. (
neato renders undirected graphs.) While installing it is beyond the scope of this post, installation is straightforward on OSX, Windows, and most Linux and BSD distributions.
Read more on Making Diagrams with graphviz…
I was recently asked if I had any advice for reading code. It’s an important skill for developers, because practice reading code leads to faster ramp-up on projects. Studying good codebases is also one of the best ways to pick up a sense for project architecture design.
1. Find Your Point of Entry
First, there’s the question of where to start. If I’m trying to get a sense for how a system fits together a whole, its main point of entry is an obvious starting place. Often, though, I’m more interested in a particular feature — understanding why awk’s implementation of regular expressions can run laps around the one in Ruby, or a cool trick like Chicken Scheme‘s “Cheney on the MTA“-based garbage collector.
Read more on Code Reading…