Tuesday, November 29, 2011

Humility in programming languages

John Backus (pdf) distinguishes two parts of a programming language: "First, its framework which gives the overall rules of the system, and second, its changeable parts, whose existence is anticipated by the framework but whose particular behaviour is not specified by it."

The framework part is all the built-in language constructs.

The changeable parts are everything we create in the language. Classes, methods, functions, modules, libraries.

Backus's point is that strong languages are a platform for developers to build on. Adding a bunch of framework -- for loops, case statements, new syntax -- might increase productivity, but it's what we can build on top of the language that makes it take off.

When Scala tries to be a SCAlable LAnguage, this in part of what scalable means. The language lets developers add to it.

For example -

Java and C# give us case statements, very restricted matching mechanisms that only work on constants. It was a Big Deal when Java added Enum and supported in case statements, in addition to int.

Scala has more pattern syntaxes, including matching strings and lists and arrays and tuples etc. Scala gives the program access to the matched parts.

F# goes one better and lets the programmer define patterns. Active patterns let the programmer create whatever matcher is needed, exponentially increasing the power of pattern matching.

For details and examples on active patterns, read my article at developerfusion.

In general, functional languages please Backus because they let the programmer create and use changeable parts in all sizes with minimal ceremony. F# active patterns exemplify this goal.

Let the language remain humble, and let its framework get out of the way of the changeable parts.

No comments:

Post a Comment