Anders Hejlsberg is explaining new features in C# 4.0, a future version, at Microsoft’s PDC. The big new feature, he says, is support for dynamic typing. Currently C# uses static typing, which means that when you call object members like methods and properties, the compiler checks that they exist or raises an error if they do not. By contrast, with dynamic typing you can call any old method or property, and they are not checked until runtime.
C# 4.0 will support dynamic typing through a new static type called “dynamic” (this raised a laugh at PDC). In other words, if you declare a variable as dynamic:
dynamic obj;
then you can call what you like as if it were a member of obj, and it will be resolved at runtime.
Hejsberg showed in his demonstration how this simplifies interop with other dynamic languages like JavaScript or Python.
Other new features are named parameters and optional parameters. This is a big win for COM interop – automating Microsoft Office, for example, from C# has always been painful because COM was designed to support optional parameters. C# got round this with an ugly hack “ref.missing”. All gone in C# 4.0.
This is interesting but doesn’t this move away from strong typing meaning that the last 25 years of covential wisdom is being thrown out the window (sorry no pun intended), or is this really just so you can write code that simplifies interop with other dynamic languages like JavaScript or Python.
Gary
More the latter in my opinion.
Tim
A Variant by any other name…