InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Proposal: A Compromise on Using Dynamic in C#

Posted by Abel Avram on Nov 12, 2009

Sections
Development
Topics
Language ,
Dynamic Languages ,
.NET
Tags
C#

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?

No comments

Watch Thread Reply

Educational Content

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.