Tech Tock

Time is of the essence.

C# Dynamic – C# 4.0/2010 New Feature

I watched the video about the new Dynamic feature coming in .Net 4.0.  Its an interview with Sam Ng and Chris Burrows who are the compiler developers who actually helped design and implement the feature.

This feature provides enhanced interoperation with dynamic languages such as Ruby and Python, with dynamic models such as Silverlight JavaScript, and with COM objects, particularly those that you find in the Office APIs. With the addition of Dynamic to C# 4.0, it is now much easier to access Microsoft Office APIs from C#.

They almost lost me when they said it was for interop & COM (features I hope to avoid), but they brought me back when they mentioned it would be helpful with the HTML DOM and Office (features that keep sucking me back in).

They talked about the DLR (dynamic language runtime) which helps with dynamic expressions.  Lots of mentions of interop with IronPython & Ruby so we’ll see if this makes those guys happy or is just a red herring.

There’s going to be a dynamic type: its syntactic sugar for object type (I’m in favor of anything sweet).  Dynamic type will help the compiler optimize, but the syntax will be the same as usual.  This is primarily for COM Interop, Dynamic C#/Reflection, and Office API’s.

Dynamic will allow for working with dynamic objects without all that nasty casting, but you need to know method names in that case, so it sounds like you wont get intellisense :(, and late bound type errors aren’t pretty either.  While getting the same error at runtime as you would at compile time sounds good, the bad part is that you’ll get an error at runtime.  More debugging…

Another use case is using a dynamic object (essentially an object type) as a parameter and the proper overload being determined at runtime.  Oh joy, imagine all the possibilities.  Now test them all…

On the other hand, if you really need to do this, it sounds like dynamic will help make things easier without much trouble for the developer.  I’m all for that.

I bet one day I’ll use this.  I hope I won’t build something embarrassing or that I regret.  At least I feel smarter listening to these guys talk.

Advertisements

November 15, 2009 - Posted by | Uncategorized | , , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: