Saturday, May 26, 2007

Erlang: I'm on DZone!

My Erlang post ended up on DZone! Wahoo!

(By the way, I'm a DZone reader, so this is particularly exciting!)

Wednesday, May 23, 2007

Erlang: The Amazingly Funky and the Amazingly Cool

Anyone who's ever looked at Erlang knows that the syntax is downright strange. For instance, Python uses "#" for comments, but Erlang interprets "8#7" as 7 in base 8 notation. Python uses "%" for modulo, but Erlang uses "%" for comments. Erlang uses "rem" for modulo, but "rem" is used as a comment delimiter in some other syntaxes.

However, I ran across some other cool tidbits. If M is a 16 bit binary value, you can unpack the first 3 bits into X, the next 7 bits into Y, and the last 6 bits into Z using the syntax:
<<X:3, Y:7, Z:6>> = M
Hence, you can parse an IPv4 datagram in a single pattern-matching operation (taken from "Programming Erlang: Software for a Concurrent World" p. 99):
-define(IP_VERSION, 4).
-define(IP_MIN_HDR_LEN, 5).
...
DgramSize = size(Dgram),
case Dgram of
<<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16,
ID:16, Flgs:3, FragOff:13,
TTL:8, Proto:8, HdrChkSum:16,
SrcIP:32,
DestIP:32, RestDgram/binary>> when HLen >= 5, 4*HLen =< DgramSize ->
OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN),
<<Opts:OptsLen/binary,Data/binary>> = RestDgram,
...
That's about as cool as it gets for implementing binary protocols!

Vim: More Tips

If you've been following along with all my ramblings about Vim, you may enjoy this other guy's rambling about Vim. I learned:
  Re-indenting:
==
Re-indent current line.
<motion>=
Re-indent block.
Grepping in vim:
:grep -r vim .
:cn Display the next grep finding.
:cp Display the previous grep finding.
:cw Open the QuickFix window to get an overview over the results.
^d
Use this instead of tab completion to see all the options.
:set spell
Turn on the spell checker.

Humor: Interviewee's Creed

God, grant me:
the communication skills to convey the things I know,
the humility to accept the things I don't,
and the wisdom to know the difference.

Friday, May 18, 2007

OS X: Aquamacs

I am a die hard Vim fanatic, as many of you know. I actually like modal editing. However, in the Erlang world, everyone seems to use Emacs, and the Erlang mode for Emacs is quite advanced. The practical thing to do is to use Emacs for Erlang and Vim (since I like it so much) for everything else. The only problem is that every time I learn something in Emacs, I tend to forget something in Vim ;) Yes, my brain is that small!

Fortunately, Bob Ippolito introduced me to Aquamacs, an easy-to-use, Mac-style Emacs for Mac OS X. Being a GUI guy, I was immediately pleased to see the nice Cocoa interface. (This is one thing I always liked about Vim, there's a native version of GVim for each operating system.) However, what's even better is that they've gone to great pains to make Emacs feel natural for OS X users. All the normal Apple shortcuts work. Even though I've taken the Emacs tutorial a quarter dozen times, using Aquamacs, I felt more productive almost instantly. The menus also helped quite a bit. I like the configuration system too; I figured out how to turn off backups without having to read the manual.

All in all, I'm not planning on giving up Vim, but using Aquamacs is making me a much happier Erlang coder.

Tuesday, May 08, 2007

O'Reilly Code Quiz


I took O'Reilly's code quiz. It was kind of nerve racking to try to answer questions quickly, but it was a lot of fun! As usual, my accuracy was pretty high, but I took too long.

Tuesday, May 01, 2007

Python: Django's Everywhere!

As a Python programmer, do you ever feel like Django has permeated everywhere? I was surfing on YouTube today, and I stumbled upon this video of Adrian Holovaty. Heh, nicely done, Adrian!