Brian Kernighan on Successful Language Design

Next case study considered by Kernighan is EQN, a mathematical typesetting language that he designed with Lorinda Cherry in 1974. The basic idea with EQN was implementing a language that made it possible to write math formulas the way they are spoken and served as inspiration to TeX:

x sup 2 + y sup 2 = z sup 2
f(t) = 2 pi int sin(omega t) dt

This syntax allowed the use of EQN by typists inside Bell Labs that were no mathematician, says Kernighan. One fundamental decision about EQN was to use pipes to feed its output to troff, basically due to memory constraints on computers at the time the language was created. Relying on existing tools is, according to Kernighan, a good approach for implementing DSLs while keeping the implementation complexity low.

Another typesetting language by Kernighan was Pic, a language meant to convert a textual description into a line drawing. Among the advantages that Pic provided were its making systematic changes easy, guaranteeing correct dimensions, and using loops and conditionals to build repetitive structures. Again, the approach was using troff as the output stage and piping into it the Pic preprocessor. This language was implemented using YACC and LEX, which made it easy to experiment with syntax and build a free-form English-like syntax that did not relied much on coordinate specification. This is how a simple flow chart would be specified in Pic:

box "input";
box "process";
box "output";

Based on the examples above, Kernighan suggests then a few principles that can explain why languages succeeeds:

  • They solve real problems in a clearly better way thanks, among other things, to their notation.
  • They are culturally compatible and look familiar. This applies, e.g., to many languages that have relied on C-like syntax to make it easy to get started.
  • They are compatible with the existing tool ecosystem and do not require buying into a complete new environment or doing away with standard tools.
  • They are open source – this is especially true nowadays, Kernighan says.
  • They have weak competition and good luck.
3 of 4

Leave a Reply

Your email address will not be published. Required fields are marked *