BT

InfoQ Homepage News Proposal: A Compromise on Using Dynamic in C#

Proposal: A Compromise on Using Dynamic in C#

Bookmarks

Jeffrey Palermo, CTO of Headspring Systems, proposes a compromise in using dynamic for C#: the ability to make an entire method dynamic while keeping assemblies static.

Commenting on a recent debate on Static vs. Dynamic Typing, Palermo noted that dynamic programming is hard when it comes to use libraries because:

you really don’t know what it supports except if the documentation is liberal and flawless.  There are no interface types to describe what properties and methods will be called once you pass the object in.  If the documentation doesn’t cover every API, you are forced to write characterization tests.

Another problem is, in his opinion:

When working with a dynamic language, you have to keep more of the system in your head in order to program.  You have to remember which object is overriding which method, and what objects have new functionality attached to them.

Both of these problems are real issues when having to deal with external libraries, but they are not such a problem for a developer working in his own code because he owns the code.

C# 4.0 introduces dynamic lookup allowing developers to declare objects of dynamic type. This feature was intended to let programmers more easily deal with objects from dynamic languages such as Python or Ruby, COM objects accessed through IDispatch, objects with a changing structure like HTML DOM or .NET types obtained via reflection. Objects of dynamic type can be used with some limitations as they usually are in dynamic languages.

Palermo proposes the introduction of a dynamic keyword in C# that would allow dynamic typing for all the objects in the method without having to explicitly declaring each as dynamic. This would allow developers who prefer dynamic typing to use it inside C# and in the meantime would leave the language static at the assembly boundary level for safety.

Is this a desirable compromise?

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.