SQLMetal woes: No sqlmetal.exe with VS 2008 Team Edition
Using Expression Blend with VS2008: Invalid project File Error

Dynamic Language Runtime: What is it?

On many blog entries around the world, specially from the bloggers from Microsoft, one would find a numerous mention about the Dynamic Language Runtime (also known as the DLR). Specially since many MS bloggers are writing a lot about IronPython, DLR is reflected in their topics. So I was questioning myself a few days ago about the DLR and how is it different from the CLR? Here are my findings.

Dynamic Programming Languages

The first and most common example of dynamic programming languages is Javascript, where one can define types and its methods at runtime. By definition, a dynamic language is a high level programming language whose behavior at runtime is similar to its behavior at compile type. So the compile time behaviors in normal programming languages can also execute at runtime for the dynamic languages. For example a class (type) can be defined at runtime or its methods can be defined at runtime in JavaScript. So a types behavioral properties can be extended at runtime. The type or the object system may be defined or changed at runtime, even the inheritance tree might be modifiable.    

Dlr1    

These behaviors can be emulated by standard runtime like the .NET CLR but, it takes a lot of work to do that. Thus the DLR is born.

Dynamic Language Runtime

First of all let me state that the CLR already has support for dynamic languages, however adding the DLR on top of CLR makes it much more easier to implement a dynamic language and makes communication between multiple dynamic languages a breeze just the way CLR did it for multiple .NET languages. This added layer on top of the existing CLR provides the following services.

Shared Dynamic Type System (I am calling this DTS)
Unlike the CTS where type safety is a crucial requirement the DTS allows us to morph the types at runtime. So we can add methods to the a type or modify it. Also two dynamic languages can talk to each other with same vocabulary.

Dlr23_2

Dynamic Method Dispatching
Ever heard of C++ virtual function tables? Dynamic dispatching is dynamically being able to change which code executes for a method at runtime. There is also another form of dynamic dispatching which is per instance dynamic method dispatching. For example at runtime we can define what code will execute for the method of a class, which is simple method dispatching. But if we are able to define for an instance of a class which code will execute for the instance of that class type that would be instance based dynamic dispatching.

Dynamic Code Generation
Code generation capabilities at compile time is called dynamic code generation. The generated code may have the capability to modify itself. For example, JavaScript eval() function is very powerful and it is able to compile and modify itself.

Hosting Capabilities
Just like the CLR, the DLR also has a hosting API.

Summary

So the DLR makes it a whole lot easier for two dynamic languages to have shared code. The keyword here is sharing. Also the DLR is built on the existing CLR. Microsoft has its DLR source code available at codeplex with IronPython project. IronPython is the first sample DLR language and MS plans to implement DLR in VB.NET 10 and next Jscript.

kick it on DotNetKicks.com

Comments

Habib

If code example was there then it would easy to understand people like me. Nice Article. Thanks.

Shafqat Ahmed

You can download IronPython source from CodePlex it has the examples, DLR soruce and even a test language.

mandana

hi
my project is about runtime programming in c#, could you give me some information or introduce useful site ,thanks.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)