Dynamic Lookup in C# 4
Charlie Calvert's Community Blog : Future Focus I: Dynamic Lookup: ""
Charlie Calvert is discussing a new feature in C# called dynamic lookup
The next version of Visual Studio will provide a common infrastructure that will enable all .NET languages, including C#, to optionally resolve names in a program at runtime instead of compile time. We call this technology dynamic lookup.
Visual Basic already has this functionality in the form of late binding.
He also provides a short sample illustrating the change.
-
static void Main(string[] args)
-
{
-
dynamic
-
{
-
object myDynamicObject = GetDynamicObject();
-
myDynamicObject.SomeMethod(); // call a method
-
myDynamicObject.someString = "value"; // Set a field
-
myDynamicObject[0] = 25; // Access an indexer
-
}
-
}
The dynamic keyword seems kind of bizarre to me. It looks like they are trying to shoehorn dynamic dispatch into .NET. Which is fine by me.
Probably the biggest language that uses dynamic dispatch in use today is Javascript. At runtime, all javascript methods are stored as members of the parent object. By using the objects prototype object, methods can be queried and added to the object. When a method is executed against an object in Javascript, first the members of the object itself are queried. If the method isn't found, the objects prototype chain is checked for the method.
I'm not sure I like using special case keywords in C#, unsafe was the first one, instead of changing the language. To me, it feels like they are trying to make C# be all things to all people. My personal feelings are the statically typed languages are going the way of the manual transmission. But trying to cram dynamic features in a static languages is a bad idea. Just get the DLR out and make it a first class runtime environment in the .NET ecosystem. And make sure that managed Javascript, not JSCript ACTUAL ECMAScript, is in there. That way the bracket-lovers will still be happy, but they won't be held back by having to write out a bunch of generic declarations and casting operations.



Pingback: dynamic dispatch - StartTags.com