CommonThread

Why a DSL?

Posted by anthony crumley, Thu Apr 05 23:58:00 UTC 2007

One of the more difficult tasks of programming is expressing complex applications with the severely limited vocabulary of general purpose programming languages. Winston Churchill once said “Golf is a game whose aim is to hit a very small ball into an even smaller hole, with weapons singularly ill-designed for the purpose.” Similarly, programming is a difficult task too often performed “with weapons singularly ill-designed for the purpose.”

By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and in effect increases the mental power of the race. Before the introduction of the Arabic notation, multiplication was difficult, and the division even of integers called into play the highest mathematical faculties. Probably nothing in the modern world would have more astonished a Greek mathematician than to learn that…a huge portion of the population of Western Europe could perform the operation of division for the largest numbers. This fact would have seemed to him a sheer impossibility…. Our modern power of easy reckoning with decimal fractions is the almost miraculous result of the gradual discovery of a perfect notation. [emphasis added]

—Alfred North Whitehead (from Code Complete, Steve McConnell, pg. 62)

When our notation is ill suited to our task the result is a lot of unnecessary work. To relieve our brains of this work and supercharge our mental power, we must discover a more perfect notation.

Some languages are better at expressing programming concepts than others. You can draw a parallel between natural languages such as English and programming languages such as Java and C++. In the case of natural languages, the linguists Sapir and Whorf hypothesize a relationship between the expressive power of a language and the ability to think certain thoughts. The Sapir-Whorf hypothesis says that your ability to think a thought depends on knowing words capable of expressing the thought. If you don’t know the words, you can’t express the thought and you might not even be able to formulate it (Whorf 1956). [emphasis added]

Programmers may be similarly influenced by their languages. The words available in a programming language for expressing your programming thoughts certainly determine how you express your thoughts and might even determine what thoughts you can express.

—Code Complete, Steve McConnell, pg. 63

By nature, general programming languages are not very expressive. Large amounts of complex and often redundant code is necessary to express sophisticated web application designs because the vocabulary is so rudimentary. Most developer’s capability to express them is severely hindered if not completely impaired. How do we improve the expressiveness of our programming languages without losing the ability to solve all kinds of problems? One solution is to enhance general programming languages with domain specific languages (DSL) providing a richer set of words to express our thoughts while retaining the ability to solve various kinds of problems.

Ruby has essentially created an enumeration DSL making it much easier to express ourselves with collections. A general purpose language simply provides generic looping that allows us to iterate over a collection and do what ever we want. The problem is that there are a number of different kinds of things we want to do and it is easy to make mistakes as we code the logic each time. Ruby solves this problem by providing methods like all?, any?, collect, each, find, find_all, inject, max, member?, min, reject, sort and many others. These greatly simplify the common iteration scenarios. The result is a much more expressive language for the original developer to express her thoughts and subsequent developers to understand them.

As I mentioned previously, the yet to be named (YTBN) JavaScript framework I am building will be a DSL. Specifically it will be an Internal DSL that will enhance JavaScript’s expressiveness related to DHTML, the model view controller design pattern, and rich internet applications. Why a DSL? I believe it is a notation that will relieve our brains of unnecessary work freeing their power to create beautiful works of software. Also, it will provide a vocabulary that allows us to express rich internet applications in a succinct and elegant way. Hopefully those who had difficulty expressing them before will be liberated from the bondage of Turing complete languages. :)

Filed Under: Pseudo | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.




Recent Articles

Categories