BT

Proposal: A Compromise on Using Dynamic in C#

| by Abel Avram Follow 9 Followers on Nov 12, 2009. Estimated reading time: 1 minute |

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 Stage
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.

Tell us what you think

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

Email me replies to any of my messages in this thread
Community comments

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT