Today was one of those pleasant days when I know it’s not the time for serious programming.
I had a lovely twitter conversation with Dimitri Fontaine, Tony Finch, and Jan Lehnardt. I started out wanting to recommend a data structure to @rahul-mr for easily garbage collecting Snabb Switch’s ethernet forwarding table. Trouble is, I don’t know the name of the data structure, so I posted this implementation in a gist and asked if anybody knows what it’s called. Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
And the twitterverse helped me rewrite this much more concisely:
1 2 3 4 |
|
which I find rather aesthetically satisfying.
Rewriting code more concisely is one of my favorite activities. Lisp is my usual tool of choice for this purpose, so I tried a translation just for fun:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
and I found it interesting that the Lua version is so much more compact than the Lisp version. Sure, I’ve compacted it with whitespace tweakery and so on, but each version is as concise as I feel comfortable making it. So I wonder if Lua is becoming my preferred vehicle for writing pseudo-pseudo-code and indulging in cutenesses?
Then having cuteness cross my mind I couldn’t help but think back to cute code I’ve worked on before. I wrote my own favorite bit of cute production code in the OLPC firmware HD Audio driver. You see, the firmware is allowed to hard-code knowledge of the physical design of the laptop and motherboard. This bit of firmware code tells the audio chip explicit details such as the size and color of each physical audio jack in the laptop. The chip can later provide this information to the operating system for presentation to a user, for example in an audio mixer application.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
The code reads a bit like english - 1/8” pink left mic-in jack - but is actually purely imperative Forth code that was inspired by the wonderful book Thinking Forth.
So it goes!
P.S. I never did work out the canonical name of the data structure. Please drop me an email on luke@snabb.co
if you know.