Welcome to MSDN Blogs Sign in | Join | Help

Future Focus I: Dynamic Lookup

by Charlie Calvert and Mads Torgersen

What is Future Focus?

This is the first of a series of monthly posts designed to give insight into the C# team’s current plans for future versions of Visual Studio. Each post will highlight one or more key subjects that will impact users of the C# language.  

It is important that readers of this column have the right expectations. The information in this column is meant to be a helpful guideline for C# developers, and not a binding commitment. We are not attempting to give a complete list of features in the product, but only to share what we can in a way that will be easily accessible to all C# developers. The Visual Studio schedule, unforeseen technical problems, intellectual property rights and competitive pressures may impact our schedule or our ability to share our plans. We will, however, do our best to keep you up to date on the latest news from the team as they design and implement future versions of the C# language.

Future focus is not designed to present a detailed specification of future features. Instead, its purpose is to outline in broad strokes, and easy to understand terms, the directions that team will take in the future.

Dynamic Lookup

The next version of Visual Studio will provide a common infrastructure that will enable all .NET languages, including C#, to optionally resolve names in a program at runtime instead of compile time. We call this technology dynamic lookup.

Work on support for dynamic lookup was begun in the CLR, but soon became part of the Dynamic Language Runtime, or DLR. The DLR provides the infrastructure on which a common set of dynamic tools can be built. For instance, the DLR provides the infrastructure for both IronRuby and IronPython. It will be the infrastructure on which the C# team implements dynamic lookup .

Support for dynamic lookup is already available in Visual Basic for .NET, where it is often known as “late binding”. The new release of .NET will provide C# developers with similar functionality, while at the same time providing a shared infrastructure for runtime name resolution across all .NET languages, including VB.

Useful Scenarios

There are three primary scenarios that will be enabled by the new support for dynamic lookup:

  1. Office automation and other COM Interop scenarios
  2. Consuming types written in dynamic languages
  3. Enhanced support for reflection

Office Automation

In the next version of Visual Studio Office automation will be easier. Developers will be freed both from the need for using a bulky type library, and the need for including optional arguments in their method calls. The support for Office Automation will be part of a general effort to enhance support for COM Interop and Office PIA.

Consuming Dynamic Languages

Dynamic languages such as IronPython or IronRuby are becoming increasingly popular. At this time, those languages can call C# code, but we can’t easily call into their code. The next version of Visual Studio will simplify the steps C# developers take to call into IronPython or IronRuby classes. This will give developers access to a useful existing code base, and an alternative way to write new code.

Call Reflection

C# developers can currently use reflection to instantiate classes and call arbitrary methods that are not known at compile time. The dynamic extensions to the C# language will make it much easier to make such calls.

Syntax

The syntax that will be used for dynamic lookup has not yet been finalized. The code that I show here is therefore only a tentative sketch that reflect the team’s evolving plans.

The team is currently considering adding the keyword dynamic to the language and using it to demarcate a block of code:

static void Main(string[] args)
{
    dynamic
    {
        object myDynamicObject = GetDynamicObject();
        myDynamicObject.SomeMethod();         // call a method   
        myDynamicObject.someString = "value"; // Set a field
        myDynamicObject[0] = 25;              // Access an indexer
    }
}

All the code that occurs in a dynamic block will potentially support dynamic lookup; even if the accessed members are not known by the C# compiler to exist, it will allow the code. At runtime the DLR will look at the actual object referenced by myDynamciObject for members with those names. It will access them if they do indeed exist, otherwise an exception is thrown. Outside of a dynamic block developers can only call C# code statically, just as they do today.

The details of the compile time process have not yet been determined. For instance, the compiler might treat all methods in a dynamic block as dynamic and only attempt to resolve them at runtime. Alternatively, it might first try to resolve them statically, and if that fails it will attempt to resolve them dynamically at runtime. As we gain more clarity on our design of this technology we will publish many more details.

Summary

In this edition of Future Focus you have learned about the team’s current plans for enabling dynamic lookup in the next version of the C# language. You have seen one tentative plan for enabling this syntax. You have also seen that dynamic lookup will be enabled for three code scenarios:

  • Office Automation in particular and COM Interop in general
  • Consuming types written in Dynamic languages
  • Enhanced support for Reflection

Mads Torgersen is a Senor Program Manager on the C# team. He has been working closely with Anders Hejlsberg and other key members of the C# team as they develop the plans for the next version of the C# language. Charlie Calvert is the C# Community PM.

 

kick it on DotNetKicks.com
Published Friday, January 25, 2008 12:10 PM by Charlie Calvert
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Future Focus I

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Friday, January 25, 2008 3:14 PM by DotNetKicks.com

# re: Future Focus I: Dynamic Lookup

What's the usability scope of the "dynamic" keyword?  If it's only inside method/property members, that will be quite limiting on its use.

Friday, January 25, 2008 5:16 PM by Jimmy Bogard

# re: Future Focus I: Dynamic Lookup

Interesting concept.  I imagine the runtime will do all sorts of nice optimizations to make sure that this runs nicely.

However, given what you have now, what's to stop you from implementing this as a compiler trick?  What is integration with the CLR going to give you over having reflected calls emitted by the compiler?

Friday, January 25, 2008 5:25 PM by casperOne

# re: Future Focus I: Dynamic Lookup

casperOne,

The biggest thing that this gives you over reflection is ease of use. This is a much simpler syntax than we had through reflection as we know it today.

Also, there is new functionality here in terms of COM interop and interaction with dynamic languages. Today those features are either missing altogether, or are very hard or awkward to use.

I think it is a little early to start talking about performance. We are really giving you an early look at this technology, and it will be some time before we see it in more depth. Certainly I hope the performance will be great, but it is too soon to start making any claims.

Friday, January 25, 2008 6:06 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

Jimmy,

The scope in the current plans would be to have it work only inside a method or property implementation, as shown in the article above. But our plans are still under development.

Tell me what you are thinking about. Would you like to see it have class scope? Would you extend the scope across an entire namespace?

It would be very wrong of me to give the impression that this is your chance to design a feature. That is not the case. But this is a chance for you to give us feedback. What would you like to see?

- Charlie

Friday, January 25, 2008 6:16 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

The intention is indeed for this to be efficient. A big part of the DLR's job is to provide efficient execution infrastructure for code that is looked up at runtime - such as that of dynamic languages - Python, Ruby etc.

/Mads

Friday, January 25, 2008 7:58 PM by Mads Torgersen (MSFT)

# Welcome to my new place

Hi all, it's me again. For those who don't know me, I'm a tester on the C# IDE team at Microsoft. I already

Friday, January 25, 2008 11:23 PM by Kirill Osenkov

# re: Future Focus I: Dynamic Lookup

@Charlie

Our typical use for late-binding was Interop/Office scenarios.  We would create a single class to act as a facade over these COM resources.

Sometimes COM classes can be expensive to instantiate.  In these cases, we would instantiate them at the constructor and set a private field.

Also, COM references would frequently cross method (but not class) boundaries as we would do normal internal refactoring.

For anything but dead simple scenarios, it would be difficult to accomplish what we need in one method.  As large as the Office interfaces are, there's not a whole lot you can accomplish inside a single block before it gets complex and unmaintainable.

In these cases, I wouldn't necessarily need namespace-scoping, but file or class scoping would be sufficient.

Friday, January 25, 2008 11:53 PM by Jimmy Bogard

# Welcome to my new place

Hi all, it's me again. For those who don't know me, I'm a tester on the C# IDE team at Microsoft

Saturday, January 26, 2008 12:24 AM by Noticias externas

# C#.Next What do you expect?

I have been searching for any clue about the next version of C# and what the features to be included,...

Saturday, January 26, 2008 6:10 AM by Bashmohandes

# re: Future Focus I: Dynamic Lookup

Great news that you are considering changing the access to Office Automation. I hate the optional parameters and the "missing, missing, missing" throughout the C# code.

:-)

Klaus

Saturday, January 26, 2008 7:47 AM by Klaus RM

# re: Future Focus I: Dynamic Lookup

First of all, I think it is a great idea to give us an early insight in your future plans and let us give early feedback.

My suggestion is to limit the scope of the dynamic-block to a particular variable or property and also to allow it in the declaration of (local) variables or maybe even properties and fields. This is, because in most cases you don't want every lookup in your dynamic block to be dynamic, but only to some variables that e.g. contain COM-objects.

So in the example above, I would rather see:

object myDynamicObject = GetDynamicObject()

dynamic(myDynamicObject)

   {

       ...

   }

or:

dynamic object myDynamicObject = GetDynamicObject();

...

Of course something like myDynamicObject.Foo.Bar would also work, but something like:

object foo = myDynamicObject.Foo;

foo.bar

would not work and would require another dynamic modifier on the foo declaration.

If you allow the dynamic flag on property or public field declarations, you could do it with some sort of attribute, but I'm not sure if this is a good idea, because developers using these properties or fields may not be aware of the fact that they are opting in for dynamic lookup. Also this may encourage bad programming style, where someone exposes lots of "object"-properties and relying on the dynamic lookup, where he could use other mechanisms to give the caller a statically typed way to access these properties.

A compromise would be to allow this flag only in private property or field declarations, which would make a class scoped dynamic keyword (as suggested above) unnecessary and still allow for static typing for everything not marked dynamic in the class.

I would love to hear your feedback on this.

Saturday, January 26, 2008 8:00 AM by Thomas Krause

# re: Future Focus I: Dynamic Lookup

What kind of control do I have over it?

That is, do we have a method missing hook?

Saturday, January 26, 2008 12:02 PM by Ayende Rahien

# re: Future Focus I: Dynamic Lookup

Finally, some news for next version coming up...

Interesting ..., i ll give my feedback ...

at first sight it seems to provide easy way for reflection...but there can be some interesting talks to it, like scoping or performance related..

Saturday, January 26, 2008 1:28 PM by GauravKalra

# re: Future Focus I: Dynamic Lookup

would be awesome of this worked on anonymous types

Saturday, January 26, 2008 8:17 PM by Vijay Santhanam

# Link: C# Future Focus

Charlie Calvert has posted an article that is co-authored by Mads Torgerson on one possible implementation

Sunday, January 27, 2008 1:50 PM by Bill Blogs in C#

# re: Future Focus I: Dynamic Lookup

What about the return types of the members you call dynamically. If we write something like:

string x = (string)myDynamicObject.SomeStringMethod();

would the runtime call SomeStringMethod and then try and cast the result to a string or check that the result can be cast to a string when it dynamically binds and throw an exception at bind time if it found that it was not possible?

Would the runtime attempt to bind the entire dymanic block before it executes it (better since this would be more defencive) or dive in and try its best to perform the calls (and possibly cause an exception after only some of the calls had run)?

Sunday, January 27, 2008 9:37 PM by Tali

# re: Future Focus I: Dynamic Lookup

Adding to the Scoping of the Dynamic Object. We too use the object at the class level. For example we write an export class that has a single handle into Excel. Having the scoping at the method level will severly limit the cross method calls. Unless we can declare the object as DynamicObject in the calling method.

private void CreateHeaders(dynamic object excelObject, string[] headers) {

dynamic(excelObject) {

}

}

Monday, January 28, 2008 8:17 AM by Mark Dykun

# re: Future Focus I: Dynamic Lookup

Jimmy and others who addressed the scoping issue:

Taking into account the fact that our plans are still fluid, and nothing is finalized yet, the current thinking is that there will be no reason to consider a dynamic variable as anything special, and so it can be declared as we would in standard C# 3.0 code. For instance:

class MyClass

{

  object myDynamicOfficeObject;

  public void Method01()

  {

       dynamic

       {

            myDynamicOfficeObject = GetMyDynamicOfficeObject();

            myDynamicOfficeObject.Format();

       }

  }

   public void Method02()

   {

       dynamic

       {

           myDynamicOfficeObject.SelectRange();

       }

  }

}

If one calls Method01() first, then myDynamicObject will still be fully initialized and in scope when one calls Method02().

The idea of declaring an entire object as dynamic is also in play, but there is a concern that a broad granularity of that type is not right for C#. So currently we are leaning toward the syntax shown above.

But all of your suggestions are being taken into consideration and we appreciate your feedback. It is valuable.

- Charlie

Monday, January 28, 2008 1:29 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

Mmmm that sounds so VB... does it mean that the F# tunics have left the team and hand been replaced again by the VB Ties?  

Monday, January 28, 2008 6:04 PM by Olmo

# re: Future Focus I: Dynamic Lookup

It's interesting because there's a C9 video where Anders goes on record saying that he'd think twice before putting this kind of feature into C# rather than leaving it to VB.NET. I guess market pressures are such that MS need to ensure they have something that ticks the Dynamic Box. Given that the CLR is meant to be all about using the best language for the job I don't quite see why MS don't put more effort into promoting *mixed* language solutions - rather than trying to shoehorn every language idiom and school into C#...

Tuesday, January 29, 2008 5:32 AM by Tom Kirby-Green

# re: Future Focus I: Dynamic Lookup

What I don't understand:

If everything inside the "dynamic"-block uses  dynamic lookup, then you'll loose type safety for everything inside this block, not just the objects you're really needing it for. This is a much broader granularity IME than declaring a single object as dynamic and leaving all the other objects typesafe.

In a typical scenario you'll need every access to a specific object to be dynamic. If you just declare this single object dynamic, you'll have fewer dynamic lookups than having many dynamic blocks in a class that contain dozens of other objects that would normally be just fine with static lookup, but now use dynamic lookup, just because a single object in this block needs it.

Tuesday, January 29, 2008 11:40 AM by Thomas Krause

# re: Future Focus I: Dynamic Lookup

Thomas,

Thank you for this helpful comment. As you know, this is one of the subjects that is still very much under discussion. For instance, the team is considering first attempting to resolve all code in a dynamic block statically, and using dynamic lookup only if the static calls can't be resolved at compile time. The team will take your feedback into account and I'll work to get updates to the community if and when the status on these issues changes.

- Charlie

Tuesday, January 29, 2008 1:28 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

Thomas,

Thank you for this helpful comment. As you know, this is one of the subjects that is still very much under discussion. For instance, the team is considering first attempting to resolve all code in a dynamic block statically, and using dynamic lookup only if the static calls can't be resolved at compile time. The team will take your feedback into account and I'll work to get updates to the community if and when the status on these issues changes.

- Charlie

Tuesday, January 29, 2008 1:28 PM by Charlie Calvert

# Community Convergence XL

Welcome to the fortieth issue of Community Convergence. This week we have two new releases of note: We

Tuesday, January 29, 2008 6:15 PM by Charlie Calvert's Community Blog

# Community Convergence XL

Welcome to the fortieth issue of Community Convergence. This week we have two new releases of note: We

Tuesday, January 29, 2008 6:24 PM by Noticias externas

# re: Future Focus I: Dynamic Lookup

I agree with Thomas.  I think that the typical scenario has us using dynamic lookup for all references of a single object, so it makes sense to declare the object as dynamic rather than a block of code.  Something like this:

class SomeClass

{

   dynamic object _myLateBoundMemberObject;

   object _myStaticallyBoundMemberObject;

   private void SomeMethod()

   {

       dynamic object myLateBoundLocalObject;

       object myStaticallyBoundLocalObject;

   }

}

~Steve

Tuesday, January 29, 2008 10:10 PM by Steve

# re: Future Focus I: Dynamic Lookup

How about using -> instead of . for dynamic lookup? I'm only half joking!

Wednesday, January 30, 2008 5:20 AM by commenter

# re: Future Focus I: Dynamic Lookup

I agree with Tom (and Anders, apparently). It is silly to try to make C# everyman's language. Why can't the C# language team admit that it's ok to have statically typed languages for some purposes and dynamically typed languages for other purposes? You don't have to take EVERY SINGLE programming convention or idea or trick and find a way to squeeze it into C# somewhere. Personally, I WANT C# to stay away from dynamic language features; I use it because I want a statically typed language. When I want a dynamically typed language, I can reach for one of the many available. You don't have to try to be everything to everyone.

That said, if you are hell-bent on doing this regardless of its advisability, then I also agree with Thomas. If you take a step back from the technology and look at the typical use cases, usually the only times you need to use dynamic invocation is because you have created an object for which you do not have static access to its members, i.e. it was constructed from a dynamic language library, or through reflection. Therefore, it would make a lot more sense for the dynamic keyword to be used at the variable declaration level, allowing all calls on that variable to be dynamic without having to clutter up all of the code that might use that variable with dynamic blocks.

Wednesday, January 30, 2008 11:12 AM by David

# re: Future Focus I: Dynamic Lookup

If I understand what your doing, this is really just another C# compiler trick where your just going to replace it in IL with a reflection version.

If got that right, then I also prefer a new Dynamic Lookup method operator instead.

'->' might cause many C++ refuges some heartburn, so how about:

myLateBoundLocalObject'Method1()

or

myLateBoundLocalObject~Method1()

or

myLateBoundLocalObject@Method1()

or

myLateBoundLocalObject..Method2()

or even reverse it to make them stand out more

aka

Method1() of myLateBoundLocalObject

or

Method1()@myLateBoundLocalObject

I think if a good operator is found it would make the code much cleaner.

I personnally like the '..' version as it would be easy to remember.

One period for Static bound calls,

Two periods for Dynamic lookup.

-Pablo

Wednesday, January 30, 2008 12:22 PM by Pablo

# re: Future Focus I: Dynamic Lookup

Quick suggestion: could the "dynamic" modifier be implemented as an attribute?  That way the attribute could be applied to a variable, class, function, etc.  That would address the scope issues presented earlier, and it would be easier to read and comprehend the code.

Wednesday, January 30, 2008 12:29 PM by Paul

# re: Future Focus I: Dynamic Lookup

Kinda OT, but since somebody important could be reading this...

Can we /please/ have something like ':' operator, so that following could be written:

string greatGrandFatherName = person:Parent:Parent:Parent:Name;

...instead of tedious...

if (person.Parent == null) return null;

if (person.Parent.Parent == null) return null;

if (person.Parent.Parent.Parent == null) return null;

return person.Parent.Parent.Parent.Name;

OK, this isn't the best example, but there are many uses for this (especially in ORM) and it makes syntax so much cleaner, IMHO.

LP,

Dejan

Wednesday, January 30, 2008 4:35 PM by Dejan Stanic

# re: Future Focus I: Dynamic Lookup

This reminds me of the times when Delphi first added late binding features in order to support COM automation scenarios...

Wednesday, January 30, 2008 8:22 PM by Octavio Hernandez

# C# vNext Revisited

I often rethink or have additions to my posts. This topic of what's coming in C# vNext is definitely

Wednesday, January 30, 2008 8:40 PM by Matthew Podwysocki's Blog

# re: Future Focus I: Dynamic Lookup

Hi. Thanks for a great post Charlie and Mads!

I'll post some of my feedbacks here.

What about a dynamic block and a new late bound operator (.. for example):

object myObject = GetDynamicObject();

dynamic

{

 int i = myObject..GetValue();

 string s = myObject.ToString();

}

This way you spesifically choose to do late binding and show exactly here you want it. But this kind of breaks the nice typesafe static nature of C# I guess...

Thursday, January 31, 2008 4:35 AM by Hans Olav Stjernholm

# re: Future Focus I: Dynamic Lookup

This is so fun I have to put out another idea...

What about some kind of inline interface declaration?

object myObject = GetDynamicObject();

dynamic

{

 interface (myObject)

 {

   void SomeMethod();

   int GetSquare(int v);

 }

 catch

 {

 }

 myObject.SomeMethod();

 int i = myObject.GetSquare(100);

}

This way you both declare a dynamic section and declare the exact members you need.

There's actually no real late binding, just a syntactic sugar for reflection lookups.

Another nice feature here I think is the possibility to catch if the lookup fails.

You could even start a new interface failover declaration inside the catch.

Thursday, January 31, 2008 4:42 AM by Hans Olav Stjernholm

# re: Future Focus I: Dynamic Lookup

David,

Thank you for your comments. The team will consider them carefully. Please note that the proposed C# features discussed in this post are not designed to convert C# into a dyanmic language, only to make it possible to call code written in a dynamic language and to make COM interop simpler.

I and others on the team hear and appreciate what you are saying in your second paragraph about the declaration of dynamic variables and I will pass that information on to everyone on the team.

- Charlie

Thursday, January 31, 2008 4:52 AM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

After posting the -> 'suggestion' I decided that '..' would be a reasonable looking alternative. So there you have it - independent evolution of the same syntax idea from multiple people - it must be a good idea :)

The whole thing reminds me a bit of the old VB syntax for accessing fields on a recordset:

Sn!FieldName 'instead of Sn.Fields("FieldName")

Thursday, January 31, 2008 5:03 AM by commenter

# re: Future Focus I: Dynamic Lookup

I vote strongly in favour of Thomas Krause's suggestion.

I think a tagged block (similar to "unsafe") that changes the language rules for all code inside it would be a bad idea.

Firstly, if you made it affect all types within the block, that's too coarse-grained - what if some calls could be static? This immediately leads to the idea of mixing dynamic and static lookup, as mentioned.

Secondly, the main reason for using that tagged block approach is because you want to clearly call it to the attention of someone reading the code, but in fact if all the code in the block happens to be statically resolvable then the dynamic block would not make any difference, and so would be completely misleading to anyone reading the code. It's like a worrying comment that might have genuine implications, but might not.

Far better to have a pseudo keyword made of two tokens, "dynamic object", which declares a reference type on which method/property access is always dynamic. This can then be used on local variable or member declarations.

As for making it clear to the reader of the code, Visual Studio can do a much better job of this by highlighting all method/property accesses on dynamic objects. It would be great if they had a grey background or something like that - they'd stand out a mile and it would give instant feedback to explain why there was no intellisense happening.

Thursday, January 31, 2008 5:11 AM by Daniel Earwicker

# re: Future Focus I: Dynamic Lookup

Thomas, Daniel, Commenter, others,

Thanks for these suggestions. This is great feedback and it is very much the type of thing we were hoping to see. I'll make sure all your ideas are passed on.

- Charlie

Thursday, January 31, 2008 5:49 AM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

I have to agree with Thomas on this one

dynamic object myDynamicObject = GetDynamicObject();

I think that c# should remain explicit when it comes to this new feature of dynamic objects. I much rather declare an object as dynamic.

Imagine a scenario where I have a private member variable that is dynamic. If we state it as such on the declaration we will not have to litter our code with

dynamic {

...

}

on each of the 10 functions that we require to use that object.

This also has the added benefit that you can specify a return value of dynamic object on functions. You would then have the ability to know which functions return dynamic objects on that 3rd party API that I am consuming as a programmer.

I think it is important for c# to remain a language that is explicit in telling the compiler how to do things. I would not like to see the compiler trying to get overly smart and trying to guess within a dynamic region what really *is* dynamic and what is *not*

On a side note I think Dejan has brought up an important missing nicety in c#. I too would like to see a null dereferencing operator of some sort in the form of myobj.?property  or with a symbol of your choice

Thanks,

Anastasios

Thursday, January 31, 2008 6:34 AM by Anastasios Yalanopoulos

# re: Future Focus I: Dynamic Lookup

Wouldn't it be cool to support both late binding and intellisense.

I think optionally declaring methods and properties in the variable declaration could do.

public class Program

{

// Without intellisense

dynamic object dynObject = GetDynamicObject();

// With intellisense

dynamic object dynObject = GetDynamicObject()

{

void SomeMethod();

}

}

This way you can opt for intellisense according to own needs.

And it could also be possible to declare inline:

dynamic (dynObject)

{

int GetSquare(int value);

}

int i = dynObject.GetSquare(100);

Thursday, January 31, 2008 6:59 AM by Hans Olav Stjernholm

# re: Future Focus I: Dynamic Lookup

This is kind of off-topic, but since we're talking about C# future I would like to suggest an implementation for optional parameters.

I understand why C# doesn't allow them since this transfers control from the user of a method to the implementor,

and the implementor can choose to change default values at any time, possibly breaking the code using it.

But what about declaring default values and letting intellisense auto-insert them for you?

Here's a code example:

public void PlaceOrder(int orderID, int price = 100);

Then, when you write PlaceOrder intellisense will autofill the price param to be 100 if you want it to.

This doesn't make a lot of sense when there's one parameter defining a default value,

but with 10 it could really boost productivity.

Thursday, January 31, 2008 7:12 AM by Hans Olav Stjernholm

# re: Future Focus I: Dynamic Lookup

I hope this just uses reflection under the hood and doesn't alter the .NET framework to accomodate late binding in anyway. Much like var in C# is just a compiler trick

Thursday, January 31, 2008 12:41 PM by Chris

# re: Future Focus I: Dynamic Lookup

Maybe this syntax instead:

var myDynamicObject = p as dynamic;

myDynamicObject.SomeMethod();         // call a method  

myDynamicObject.someString = "value"; // Set a field

myDynamicObject[0] = 25;              // Access an indexer

Thursday, January 31, 2008 6:34 PM by zproxy

# re: Future Focus I: Dynamic Lookup

I do this today by using a PythonEngine instance in my C# applications. It's clunky but it works. The PythonEngine instance acts as the scope for the dynamic code. I can inject scripts into the engine using Execute() and fetch objects from the engine with Evaluate(). I use this sort of "dynamic layer" at the lower edge of my client applications to dynamically generate ClientBase<T> derived instances from WS-MetadataExchange using classes from the System.ServiceModel.Description and System.CodeDom namespaces. Imagine a SVCUTIL-free lifestyle. No proxy generation at all. It's nirvana, really.

I like Thomas Krause's proposed model where the objects to be used within a dynamic scope could be obtained outside of that scope because it would make what I'm doing with Python embedded in C# much simpler. Of course, I probably wouldn't be using Python to glue the WCF clients and services together with C# 4.0 if it supported what Charlie's talking about. But it would need to be done as Thomas describes to make it really fluid. Thomas' reply on 28 Jan at 13:29 seems to indicate that the C# team might be leaning this way. And that's good because the main problem I have today is making the dynamic Python code reach out of the dynamic scope to access object references obtained in the static scope. It's possible but really messy.

While I'm in here and on the topic of language futures, how about a policy attribute that I can attach to a class that forces it to be instantiated within a using statement? In other words, for a class that implements IDisposable, give me an attribute that I can mark the class with so that any attempt to instantiate the class in a way that would not invoke IDisposable::Dispose would simply not compile. Man, would that be helpful?!

- Kevin

Thursday, January 31, 2008 7:08 PM by wkhazzard

# Episode 1 of our Weekly Recap Show is up

Kudos to Brian for editing everything last night, I think he's sleeping on my couch right now, but our

Friday, February 01, 2008 11:32 AM by Dan Fernandez's Blog

# Episode 1 of our Weekly Recap Show is up

Kudos to Brian for editing everything last night, I think he&#39;s sleeping on my couch right now, but

Friday, February 01, 2008 12:04 PM by Noticias externas

# Brian Keller and Dan Fernandez: Name this Show!

This is Episode #1 of &lt;insert.name.here&gt;, a weekly recap show of our favorite things for developers

Friday, February 01, 2008 12:04 PM by Noticias externas

# re: Future Focus I: Dynamic Lookup

Personally, I have to side with the guys that like C# to stay static.  LINQ is about the extent of "dynamic-ness" that I can tolerate.  

Class Libraries written in IronPython callable by C#?  I honestly can't see many truly indispensible class libraries written in IronPython that couldn't otherwise be rewritten in a much more performant way in C#.  

Granted, usability is key here, but are we in the community asking for this?  My assertion is "USE VB" since VB frankly is so close to C#, yet still has the late binding techniques built in.

Friday, February 01, 2008 1:19 PM by Eric Newton

# re: Future Focus I: Dynamic Lookup

Eric, there's a language for people like you (the instinctively conservative).

It's called Java. ;-)

Friday, February 01, 2008 3:05 PM by commenter

# re: Future Focus I: Dynamic Lookup

Eric, I understand your thinking about keeping C# statically typed. I sometimes wonder if the current duck typing pendulum has just swung to the far end of its period as it's known to do every few years. But I don't think so. This time, I think there is enough maturity in the marketplace that people are beginning to wonder why they can't have the best of both worlds.

My response above about my experiences embedding Python in C# is an expression of the fact that I love the type safety of C# most of the time. But when it's time to do something dynamic, I regret having to step out of C# (or into deep reflection and lots of CodeDom trickery) to do it.

Speaking of performance: for the dynamically-generated ClientBase<T> invocation of a WCF service in a tight loop versus using a statically-bound, SvcUtil-generated proxy called directly from C# that I described above, there is no difference in performance. The only real difference is that I never had to use SvcUtil in the former case and I really like that. So I can envision a world where static, early-binding and dynamic, late-binding get along just fine.

Friday, February 01, 2008 6:27 PM by wkhazzard

# C# Futures - Dynamic Code Blocks

C# Futures - Dynamic Code Blocks

Saturday, February 02, 2008 1:05 PM by brute forced brilliance

# re: Future Focus I: Dynamic Lookup

This is an exciting feature.  I have several comments.

1. I really like the .. operator idea either instead of or in addition to a dynamic block.  This is even more important in a maintainence scenerio than in new code.  If one is adding 2 dynamic calls to some existing code the choices are a) 2 dynamic blocks or b) subtly changing the semantic of all the method calls between them.  I really want more control over when I use dynamic invocation.

2. I hope you will expose the the name lookup logic through system.Reflection as well.  I have been trying to write a generic "accessor" class that uses reflection to allow unit tests to access private and protected members of production classes.  Doing the name resolution, based on a string member name, is easy to do wrong, and proving very difficult to do right.  I would enjoy being able to give reflection a name and say "find me the member, public / private  ... etc, that this name would map to."

3. WHat is going to happen when you do a Dynamic call on a RealProxy descendent.  I hope that it just calls Invoke with the method name and arguements, and lets me work it out.  (This would let me define some test objects with a very flexible interface.)

4. Add another vote for the : operator proposed by Dejan Stanic.  I see this pattern all the time, especially when using Linq.

John Melville

Saturday, February 02, 2008 6:34 PM by John Melville

# January 2008 Recap

I've had a policy against posting on big news that's likely to be common knowledge in the Microsoft development

Sunday, February 03, 2008 4:59 AM by Jon Galloway

# re: Future Focus I: Dynamic Lookup

This is the kind of feature that should be introduced with extreme care, since a) it's too easy to implement (so the temptation to include it will be high, even if consequences have not been considered thoroughly) and b) if badly done, it can spoil forever our beloved language.

Strongly agree with others that a dynamic {} block is not the best solution, whether dynamic in that context means "every member access will be dynamically looked up" (too coarse-grained) or "access to members not found at compile time" (also coarse-grained and may complicate understanding of the code).

Explicitly supporting "dynamic" in front of "object" in declarations (as Daniel proposes) seems much better to me. For instance, in the example of wkhazzard one could define a method:

public class ProxyGen

{

 dynamic object GetProxy() { /*...*/ }

}

and then the client would use:

 ProxyGen p = new ProxyGen();

 dynamic object cli = p.GetProxy();

 cli..Whatever();

I also support having a special operator (I'd prefer ->, but it's already used in unsafe blocks), so that these dynamic method calls are explicitly marked in code.

Best regards,

Octavio

Sunday, February 03, 2008 8:15 AM by Octavio Hernandez

# re: Future Focus I: Dynamic Lookup

The idea of adding late binding to C# is a good one, but am not sure that going down the path of using a block marked by the dynamic keyword is a good idea.

The rationale seems to be that "dynamic" would clearly flag a block of code that will have special rules, but the problem as I see it, is that there will be no way for the programmer to go back and forth inside this block to get strong typing (without doing plenty of gymnastics).

By using the 'dynamic' block, everything inside this block that happens to be an object will be treated as a dynamic path and some errors that could have been caught will not be (accidental uses of it, return values that should really have been strongly typed).

My preference would be to additionally declare variables with a keyword, an attribute or a new type, like this:

dynamic p = GetDynamic ();

p.Hello (d.World.DoSomething ());

This has the advantage that dynamic support will only be offered for "p" in this particular context, but still get full type checking with d, d.World and d.World.Something.

Miguel.

Sunday, February 03, 2008 4:31 PM by Miguel de Icaza

# re: Future Focus I: Dynamic Lookup

Give us an interface we can implement on our own classes that allows us to implement method dispatch! The Boo lanaguage has IQuackFu - silly name but very powerful.

Something like this would be cool for C#:

class MyFoo : IDynamicDispatcher

{

  object IDynamicDispatcher.Invoke(string methodName, object[] args)

  {

     // ...

  }

  // similar for properties here...

}

then use as:

dynamic foo = new MyFoo()

foo.Bar()

Compiler translates into:

foo.Invoke("Bar", null);

Monday, February 04, 2008 7:32 AM by Andrew Davey

# re: Future Focus I: Dynamic Lookup

Miguel, what about scoping? Consider this:

ShoppingCart cart = new ShoppingCart();

dynamic jabberwocky = GetDynamicObject();

Product P = jabberwocky.SomeUnknownMethod( cart );

To do this today, I have a couple of options:

(1) I can use reflection and find the SomeUnknownMethod signature for jabberwocky that best accepts a ShoppingCart, then call it, coercing the result into a Product reference.

(2) I can instantiate a ScriptScope from the DLR, inject the ShoppingCart object using SetVariable, invoke some Python, for example, to do the work, then use GetVariable<T> to fetch the Product out of the script context.

Personally, using the DLR seems like a better, long-term, more flexible option but it us certainly heavier than using simple reflection.

I suppose the question I have for Charlie and others on the C# team is: how will late-binding in C# make it easy to write code like that above. I need to move data easily in and out of the dynamic scope from the surrounding static scope, whether it's a single object marked dynamic or a whole block. And it needs to be predictable with respect to the scoping rules in both forms. I can't help but think about how statement lambda expressions and anonymous methods reach out into the surrounding scope as needed. The problem with dynamism though is know which references should reach out and which ones should not.

I suppose the more I think about this, the more I wish that the DLR were injectable into the statically typed scope, making (2) that I described above a bit easier to write.

One last thought: assuming that it comes down to marking an object as dynamic (not a block), what would be the harm in enhancing the var "type" to do this, allowing:

ShoppingCart cart = new ShoppingCart();

var jabberwocky = GetDynamicObject();

Product P = jabberwocky.SomeUnknownMethod( cart );

instead.

-- Kevin

Monday, February 04, 2008 9:11 AM by wkhazzard

# re: Future Focus I: Dynamic Lookup

First impression:

WOW

Second impression:

I am not entirely sure... i still go "wow" but I have maybe a few concerns. The dynamic{} code might look a bit awkward. Also what about totally prototype like code, like where objects are not tied to a particular class, but instead can be shaped lateron? And aside from this, what happens when objects are modified or extended at runtime, can these changes be reflected back upon the C# world?

Anyway dont get me wrong, so far it looks great

Monday, February 04, 2008 1:25 PM by she

# re: Future Focus I: Dynamic Lookup

Maybe I have an oversimplified view of this subject, but have you considered something like this?

static void Main(string[] args)

{

   interface IMyInterface

   {

     void SomeMethod();

     string someString { get; set; }

     int this[int index] { get; set; }

   }

   dynamic IMyInterface myDynamicObject = GetDynamicObject();

   if (myDynamicObject != null)

   {

       myDynamicObject.SomeMethod();         // call a method  

       myDynamicObject.someString = "value"; // Set a field

       myDynamicObject[0] = 25;              // Access an indexer

   }

}

where the dynamic keyword tells the compiler to emit code that at runtime compares the signature of the interface with the signature of the object. myDynamicObject would be set to an instance of the interface that is a proxy to the object if they are compatible otherwise it would be set to null.  All the user of the object would compile and run as it does today.

Monday, February 04, 2008 3:40 PM by Marvin Steakley

# re: Future Focus I: Dynamic Lookup

For all the reasons Eric mentioned, and then some, please tread softly here. If you really need to do this, you can already do this. Make it too easy, and you'll have every idiot who thinks code reuse is done with ctrl-c,ctrl-v making every single call dynamically. This is the problem we currently have where people use generics willy-nilly thinking they are writing code in a generic fashion, not realizing what the compiler does when it comes across generics.

Speaking of generics, how do they match up with dynamic? Bit of an interesting topic, I'm sure.

Also, performance, performance, performance. The word Dynamic translates into "trading performance for developer convenience" in just about every case you come across. A lot of developers don't make the connection that doing things dynamically makes for extra load at run time most of the time.

Monday, February 04, 2008 7:46 PM by Jim L

# Dynamic dispatch in C#

Charlie Calvert blogged about dynamic support in C# 4.0 . I love this for two reasons. One it will enable

Monday, February 04, 2008 8:32 PM by Srivatsn's Blog

# Dynamic dispatch in C#

Charlie Calvert blogged about dynamic support in C# 4.0 . I love this for two reasons. One it will enable

Monday, February 04, 2008 9:00 PM by Noticias externas

# re: Future Focus I: Dynamic Lookup

Firstly, I apologize for my negative comment. I realize that things are early and that there are surely many other announcements in the near future.

C#1 was a great start and C#2 was brilliant. Hands down the best thing about version 2 was the work done to support generics.

However, I was extremely disappointed with C#3. Almost everything introduced was nothing more than syntactic sugar. It enabled nothing that I could not already do before.

Now comes "dynamic lookup". Again, nothing that I can not already do with reflection.

I'd like to see new features that enable new scenarios. Two in particular that I have been really missing are support for 1) generic variance and a way to do 2) generic operator overloading (can't constrain T to a static method).

With that said, I'm looking forward to hearing more about the future of C#. Hopefully the next version will be more to my liking.

Tuesday, February 05, 2008 2:15 AM by Ben

# re: Future Focus I: Dynamic Lookup

I agree with David. I use C# because it is statically typed. That is also why I stay away from VB and languages like IronPython etc. I do *not* want dynamic code in my C# code.

Carlie Calvert wrote:

"Please note that the proposed C# features discussed in this post are not designed to convert C# into a dyanmic language, only to make it possible to call code written in a dynamic language and to make COM interop simpler."

Understood. However, it should be put in a library, not built into the language. I think that reflection is sufficient, but now that we have the DLR, just extend it as needed.

Tuesday, February 05, 2008 2:49 AM by Craig M.

# Mr

Thank god!

I have recently written screeds of reflection based code - there was no other way. I was crying out for something like this. To those who say "use python" or whatever... I don't have the choice and guess most devs don't either.

Oh yeah, please give us something like Missing Method from smalltalk it adds a lot of power in dynamic dispatch use cases.

Tuesday, February 05, 2008 3:10 AM by David Thompson

# re: Future Focus I: Dynamic Lookup

Any chance of having a similar keyword in Visual Basic?  It's neat that I can already make dynamic calls in VB, but I believe it currently requires one to turn Option Strict Off.  Something more fine grained would be awesome.

Tuesday, February 05, 2008 5:13 AM by Adelle Hartley

# C# Future Focus: 动态查找(Dynamic Lookup)

C#小组CharlieCalvert在其博客发了一篇有关C#语言未来方向的文章,这片文章介绍了一个叫做动态查找的特性,它为.NET语言(包括建立在DLR上的语言)能有一个统一的动态运行时名称绑定方案...

Tuesday, February 05, 2008 8:22 AM by Adrian H.

# re: Future Focus I: Dynamic Lookup

Quote: "Now comes "dynamic lookup". Again, nothing that I can not already do with reflection"

Might I suggest assembly language? There's nothing you can't do in it, and there's none of that nasty 'syntactic sugar' you seem to object to. Seriously.

Tuesday, February 05, 2008 11:51 AM by commenter

# re: Future Focus I: Dynamic Lookup

I think it will be very cool but probably unnecessary if the .Net frameworks let using multiple planguages in a class. A special project type class extensions may be defined or may be a syntax like below can be used:

@Use Language=VB .Net

... Some VB .Net Code

@End

But by the way this may reduce readability and could make the code look uglier or messier.

Tuesday, February 05, 2008 2:49 PM by Çağlar Gülçehre

# re: Future Focus I: Dynamic Lookup

Tali,

There would still be strong type checking on variables declared in a dynamic block. If a method declares that it is going to return a string, or a DataTime, then an exception would be raised if a compatible type were not returned.

Right now, it seems likely that each call in a dynamic block will be handled individually, so that some of them might execute and then an exception would be raised if one failed. These plans are not certain, but that is the most likely scenario.

- Charlie

Tuesday, February 05, 2008 4:58 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

Commenter,

You asked:

"How about using -> instead of . for dynamic lookup"

This type of thing was discussed in depth. Early drafts of the team's plans tended to include it, but now the team is leaning away from it. No decisions have been made at this point in time, of course. And there were various different characters proposed, not necessarily focusing on the C like syntax you suggest. But still in the same general vein.

- Charlie

Tuesday, February 05, 2008 5:15 PM by Charlie Calvert

# re: Future Focus I: Dynamic Lookup

I also strongly agree with Thomas.  

I'll also throw one other option into the mix.  What about something like this

object myDynamicObject = GetDynamicObject();

myDyamicObject."SomeMethod"();

The quotes around the method name make it clear that, as far as the compiler is concerned, the name of this method is just a string, to be looked up at runtime.

To me, the main thing is to find something that doesn't require a block to be wrapped around the code, and which lets me (any my IDE's syntax highlighing) tell exactly which calls are dynamic - either by the variable they are made against (as in Thomas's suggestion) or by the way the call is written.

Tuesday, February 05, 2008 6:51 PM by John Rusk

# re: Future Focus I: Dynamic Lookup

This belongs in a library, not baked into the language.

We have reflection and we have DLR. You said that the DLR will be the "infrastructure on which the C# team implements dynamic lookup." If the existing DLR infrastructure is not sufficient, then why not just extend it? I fail to see what advantages special syntax will provide over a pure library implementation. It serves no purpose but to further pollute the language when a library is the appropriate place to be doing this.

I am strongly opposed to this.

Tuesday, February 05, 2008 6:52 PM by Jackob

# re: Future Focus I: Dynamic Lookup

Based on my experience with VB (which really already has this), I agree with Thomas & Miguel. Blocks are the wrong granularity.  Either variable or call level would be great.

Wednesday, February 06, 2008 9:06 AM by Eric Nicholson

# Dynamic Lookup en C#

L'�quipe de C# d�voile un peu plus sur les principaux prochains ajout du langage avec l'aide de rubriques nomm�s Future Focus. La premi�re de la s�rie concerne le Dynamic Lookup....

Wednesday, February 06, 2008 10:57 AM by Gabriel Mongeon

# re: Future Focus I: Dynamic Lookup

@Charlie - "The idea of declaring an entire object as dynamic is also in play, but there is a concern that a broad granularity of that type is not right for C#."

I couldn't disagree more. Declaring an entire block to be dynamic is what is too broad. Declaring a single object is a more narrow approach that allows the developer to target the dynamic calls more appropriately. Perhaps even forcing individual calls to be made using a dynamic syntax would be the right way to go. But forcing a developer to use a dynamic block every time they want to make a dynamic call just makes the code harder to read.

@Thomas - "If everything inside the 'dynamic'-block uses  dynamic lookup, then you'll loose type safety for everything inside this block..."

@Charlie - "...the team is considering first attempting to resolve all code in a dynamic block statically, and using dynamic lookup only if the static calls can't be resolved at compile time."

You're talking about early binding; Thomas is talking about type safety. They are two different things. Sure, you can still early bind to anything that is statically accessible; but for anything that is not, you turn it into a dynamic call. So the developer has no way of knowing that when he mistyped that method name, instead of getting a compiler error, it gets turned into a dynamic call instead, which results in a run-time error.

The more I think about this whole thing, the more I think it is a bad idea that will lead to long-term negative consequences. Giving developers a way to easily lookup and execute dynamic calls at runtime is a good idea; baking into the syntax of the language is not. Can you please explain why you feel it is necessary to make it a part of the language, when you could just make it a part of the reflection library, or its own library, and it would function just as well, not to mention be useful in other languages as well?

Wednesday, February 06, 2008 12:00 PM by David

# re: Future Focus I: Dynamic Lookup

David,

* Type safety

Good description.  Further to the points you've made, I think it might actually be helpful if "dynamic object" is the only kind of dynamic variable that can be declared. E.g. you can't say "dynamic someOtherClass".  That  reduces the confusion that could arise from having a mix of early and late bound calls on the same variable, since so few early bound calls are actually possible on "object".

* Why not use a library?:

I presume that the desire to put it into the language is because that gives the cleanest and most compact syntax.  I would imagine that the cleanest that a library-based approach could look would be something like this:

object myDynamicObject = GetDynamicObject();

myDynamicObject.Dyn("SomeMethod")()

In this hypothetical example Dyn(string) is an extension method, that does the reflection and returns a delegate to the named method, which we can then invoke.

The problem is in passing parameters to the delegate, even though the compiler doesn't know it's type.  That might require a language change to introduce some kind of "dynamic delegate", which is a delegate that you can call with any parameter list you like, without the parameters being checked at compile time. E.g. allow this

dynamic delegate d = ...

d("Foo", "Bar", 10, false);

instead of this

delegate d = ...

d.DynamicInvoke("Foo", "Bar", 10, false);

There might be no need to actually use the "dynamic" keyword on the delegate.  Instead, it could be set up so that all calls on delegates typed as "delegate" are dynamic  - i.e. d(params...) equates to d.DynamicInvoke(params...) - but all calls on strongly-typed delegates (i.e. subclasses of "delegate") are early bound as they are now.

While this involves less messing with the language, it still requires some change, it doesn't really support setting properties dynamically, and the syntax is a bit more ugly than a fully language-based solution.

Wednesday, February 06, 2008 3:00 PM by John Rusk

# re: Future Focus I: Dynamic Lookup

I'd much rather see something like this (as others have already stated)

dynamic myDynamicObject = GetDynamicObject();

       myDynamicObject.SomeMethod();      

       myDynamicObject.someString = "value";

       myDynamicObject[0] = 25;

or perhaps

[dynamic] IMyInterface myDynamicObject = GetDynamicObject();

The block idea is a bad idea in my opinion.  I'm sure it's easier to implement, but is that good for the language in the long run?

Wednesday, February 06, 2008 5:36 PM by Rob

# re: Future Focus I: Dynamic Lookup

The idea of the interface posted by Hans gave me another similiar idea.

I like the fact that c# is 100% type safe and I like that i can rely on that.

But even so I do see where th Dynamic typing could be nice to have.

but instead of

dynamic

{

 object MyObject = GetDynamicObject

}

how about:

internal dynamic class MyDynamicBasedClass : DynamicClassIdentifier

{

public dynamic void SomeMethodOnDynamicObject(string someargument);

public void MyWonMethod(){

//do nothing and return

}

}

That would make the coding style the same as we have it today. It would be kinda type safe. It would meet the wishes of Thomas and others and it would be very readable and intellisense enabled (with a new icon for dynamic methods/properties o.c.)

Thursday, February 07, 2008 4:25 AM by Rune FS

# re: Future Focus I: Dynamic Lookup

Lots of ideas, issues, problems, solutions...

Its actually good taking feedback from community - such brainstrorming would help in getting it right the first time - a must for a language feature like this.

I too have my suggestion:

/// start

// define an interface normally as we do now

interface theDynamicObjectInterface

{

   void SomeMethod();

   int theProperty {get; set;}

}

// Something of this sort we do currently as:

//

// theDynamicObjectInterface theDynamicObject = (ItheDynamicObjectInterface)new theDynamicObjectClass();

//

// the above syntax gives a runtime error "Unable to cast..." if iterface and class implementation do not match

//

// this behavior can be altered by an explicit interntion of developer as:

dynamic theDynamicObjectInterface theDynamicObject = GetDynamicObject();

// this syntax will automatically try to cast returned object as the specified interface and

// if there is an error, object will be set to null

// here after there are normal calls which otherwise also we do

if (theDynamicObject != null)

{

  theDynamicObject.SomeMethod();

  theDynamicObject.theProperty = 10;

}

/// end

I might me missing compiler internals here, but I guess the idea is communicated.

Points to note here:

1) One point resolution for member mapping, i.e. at the time of assigning object to specified interface

2) Full intellisense

3) No special delimiter required for call-to-call basis mapping (.. or ->, etc.)

4) No dynamic code block

Thursday, February 07, 2008 5:18 AM by Vikas Burman

# re: Future Focus I: Dynamic Lookup

what I'd really like similar to this is an infered duck typing. That way I get type safeness and intelisense but don't need adapters.

In my example the 2 methods (f1 & f2) have return types which do not implement IHasText, however they both honour the interface. A new *infer* keyword could behave like the *as* keyword and return null if a type cannot be coerced into the supplied interface. Under the hood the compiler can follow the adapter pattern or what ever clever stuff is required :-)

e.g.

IHasText{string Text {get;}}

Label f1(){}

TreeNode f2(){}

void func()

{

 var ht = f2() infer IHasText;

 // use ht.Text

}

Thursday, February 07, 2008 9:45 AM by adam s

# C# 4, part 3: Ideas from Microsoft

Microsoft haven&#39;t committed to anything in C# 4 yet. However, there have been hints about what they&#39;ve

Thursday, February 07, 2008 6:11 PM by Jon Skeet: Coding Blog

# re: Future Focus I: Dynamic Lookup

C# 4 slicing index notation ala python.

var l = Enumerator.Range(1,100).ToArray();

for (var i in l[25:75])

 Console.WriteLine(i); //prints ints from 25 to 75

including pythons start/end defaults

l[:5];// the first 5

l[96:];//the last 5

Thursday, February 07, 2008 9:18 PM by Jay R. Wren

# re: Future Focus I: Dynamic Lookup

Heres an off topic question. Recently the C++ team has released a beta of the upcoming MFC changes. Included in this are some nice UI changes that incorrorate alot of the Office/Visual Studio UI enchancements, such as docking, theming, Ribbon Bar, and more...

Is there any plans to update WInForms to include these enchancements?

Saturday, February 09, 2008 1:18 AM by SalizarMarxx

# re: Future Focus I: Dynamic Lookup

I proposed the idea on this topic a while back of using the type inferencing available through the "var" keyword to support reflective, late-bound lookup. Now, we all know that "var" isn't a type but the compiler could allow references obtained that way to bind late. For example, to reflect and find SomeUnknownMethod() at runtime, this would NOT be allowed:

MyClass m = GetMyClass();

// illegal b/c MyClass is not known

// to implement SomeUnknownMethod

m.SomeUnknownMethod();

However, this would compile:

var x = GetMyClass();

// legal b/c var allows for

// late binding on references

x.SomeUnknownMethod();

Being marked as "var", the reference x gets special dynamic treatment.

I like this better than anything else I've seen here because:

1. It is a simple extension of the type inference concept that already exists.

2. It would force certain C# developers who might use "var" a little too often (if you known what I mean) to avoid the possible dynamic side effects introduced by this enhancement.

--Kevin

Saturday, February 09, 2008 1:40 PM by wkhazzard

# re: Future Focus I: Dynamic Lookup

What a terrible idea. It seems like we keep taking this circular path with languages that takes us back to exactly where we started, but with new toys.

So much for type safety and code that can be analyzed by external tools for issues

Sunday, February 10, 2008 11:50 PM by Paul

# re: Future Focus I: Dynamic Lookup

@John Rusk,

I can certainly see your point about dynamic calls being easier if the syntax is available in the language. However, I am VERY concerned about the long term effect this feature will have on the language. Much has been made in the past about new language features starting out with "minus 100 points" (http://blogs.msdn.com/ericgu/archive/2004/01/12/57985.aspx), and that they must prove that they have significant enough value that they can overcome the inherent negative impact that adding any new feature has on a language. I am far from convinced that this feature meets that criteria. I would like to hear from the language team what they think about that issue, as well as other people in the community.

Monday, February 11, 2008 10:31 AM by David Nelson

# Más allá de C# 3.0

Una vez salidos al mercado .NET 3.5 y C# 3.0, el equipo de desarrollo ya ha comenzado a pensar en las

Monday, February 11, 2008 10:46 AM by Sobre C#, LINQ y algo más...

# re: Future Focus I: Dynamic Lookup

I think the best approach is using a special operator like ..

And how about constructing objects dynamically? Like:

Type t = typeof(SomeClass);

object dynamicObj = new t(10);

-or-

Type t = typeof(SomeClass);

object dynamicObj = dynamic t(10);

And then the runtime call the correct constructor and create the object.

Monday, February 11, 2008 11:01 AM by Danilo

# re: Future Focus I: Dynamic Lookup

So, the proposed block syntax might have two motivations that I can think of:

* It's for implementation/performance reasons. Some context will be built up and held within the block in order to perform the dynamic lookup. This can then be discarded when the block is exited. If this is the motivation then I think the syntax gets in the way of usage and any performance considerations should be 'hidden' and not emphasised in a block syntax.

* It's to deliberately demarcate dynamic lookup code so that programmers can see it being used. If this is the case then I can see the point. But at th