Parsing, Programming and Protocols

2004-05-11

Someone on the Antlr mailing list was trying to parse IMAP responses with a grammar. During that discussion, this insight on programming languages vs. protocols occurred to me:

Programming languages are designed for concise and efficient, human expression. As such, then tend to require deep grammars and parsers to help expose what the intended meaning is. Protocols are designed for one program to communicate with another other. They are generally designed to be very easy to programatically generate and receive.

In a programming language we would have "a", "a(x)" and "a[y,z]" which are very concise for a human to read and write. In a protocol we'd never see this, but instead "fetch a", "call a args x" and "index a with y, z" (or some binary encoding thereof).

Programming languages repeatedly use a small set of constructs in recursive, contextual ways because as humans we prefer to keep a small set of ideas in our heads. Protocols, instead, generally have separate constructs for each context, each suited to just its task. Computers have no problem keeping track of forty different message formats.