Jack
Jack

Reputation: 10047

Dynamic Language Runtime and CLR - what's the point of DLR?

From wikipedia's entry on DLR,

it look like the purpose of DLR is for using language like Python, Ruby...etc. Is that all to DLR? Is there any other benefits and why do you want to pick IronPython over C# for say ASP.net project or Winform app?

Upvotes: 3

Views: 392

Answers (5)

Barry Kelly
Barry Kelly

Reputation: 42182

The CLR and its underlying execution model is optimized for statically typed languages. Pretty much all the methods in the class libraries with .NET take arguments that are more precisely typed than the root of the type system, System.Object.

Dynamically typed languages require a different set of functionality in a runtime. They need the ability to efficiently execute dynamically typed code. For example, when a dynamically typed language calls a regular CLR class, it needs to convert and / or typecast each argument to the statically-defined type on the CLR class. If this isn't done carefully, it can be inefficient.

Similarly, dynamically typed languages often have an object model which isn't easily mappable to the CLR class model with explicitly typed properties, methods, fields etc. Instead, objects are often more like hashtables, buckets of key-value pairs where the keys are strings (or symbols) and the values are methods, closures, or object values themselves. The objects (and / or their types) are often extensible at runtime as well.

Since there are similarities between the dynamically typed languages, it would be useful for the commonality to be extracted out into a base set of functionality, to ease both interoperation and dynamic language implementation, as well as making it easier for CLR optimizations to be specifically focused on dynamic languages. The new dynamic keyword in C# is part of this: it uses mechanisms from the DLR to help interoperate with dynamically typed languages and object systems, such as COM automation objects, IronPython, IronRuby, etc.

Upvotes: 3

onedozenbagels
onedozenbagels

Reputation: 2252

It gives developers more options and flexibility for using the .NET CLR and all of its functionality. You can use the language that you know best, or the language that is best suited to the task at hand, whether that's C#, F#, Ruby, or whatever.

Upvotes: 1

Ali Shafai
Ali Shafai

Reputation: 5161

The new C# will use some of the features in DLR. new constructs and language elements are commng...

Upvotes: 0

Jonathan Allen
Jonathan Allen

Reputation: 70337

Do you ever get tired of writing

string firstName = (string)Session["FirstName"];

With the DLR, you could simply write

dynamic firstName = Session.FirstName;

Upvotes: 0

sipsorcery
sipsorcery

Reputation: 30734

The DLR is incredibly powerful and useful. For example with the DLR you can execute any arbitrary Ruby or Python script in an application written in C#. There are lots of other usage scenarios but the dynamic script hosting has so far been the most useful one for me.

Upvotes: 1

Related Questions