Ayende @ Rahien

It's a girl

C# vNext

Jeremy Miller asks what we want in C# vNext. I have only real one request, to have meta programming of sufficent power, after which will be able to add all the required semantics without having the compiler team to argue with.

I am not holding my breath on that one, though. I can just imagine the arguments against it (let us start from the potentail for abuse, move to version and backward compatability hell, and then move forward).

I  want to go over Jeremy's list, and see what I can add there.

  1. Mixin's - Agree 102%. This is something that would so useful, I can't realy understand how it is not already there. Make it a magic attribute, something like [Mixing(typeof(IFoo), typeof(FooImpl))], and you can get away with it with just compiler magic, no changes required to the CLR.
  2. Symbols - I am ambivelent on that one. Syntatic sugar is important, but I have other things that I would value more.
  3. Make hashes a language feature - I think that you can do it right now with this syntax:
  4. var hash = new Hash(
    	Color => "red",
    	Width => 15
    );
  5. Automatic delegation ala Ruby or Objective C - Um, isn't this just mixin?
  6. Metaprogramming! - absolutely. This is something that I have gotten to consider as basic. I am getting tired of having to fight the compiler to get the code that I want to have. The code should express my meaning, I shouldn't have to dance to the compiler's tune.
  7. Everything is virtual by default to make mocking easier - I certainly would like that, but I fear that this is not something that will be changed. AOP as a platorm concept, now that is something that I want to see.

My own request covers:

  1. memberinfo() - the CLR already has this concept, so we just need the syntax for it.
  2. Method Interception - let us start with the easy stuff, I want to be able to intercept methods from any type. I can do it now if I want to mess with the profiler API, but that is not something that I can really make use of for production.
  3. IDynamicObject - I want method missing, damn it! It is just the scratch of meta programming, but this is something that you could probably add to the compiler in a week.
  4. Static interfaces. Since we already has generics to allow us to treat types as interchangable types, I want to extend this concept by just a bit, to get it to work in a more reasonable manner.

I have a few more, but they just called my flight.

Comments

JH
11/26/2007 06:14 AM by
JH

Does this resolve mixins ? http://msdn2.microsoft.com/en-us/vcsharp/bb625996.aspx

Andrey Shchekin
11/26/2007 07:27 AM by
Andrey Shchekin

Have you read a JavaGI paper (http://homepages.cwi.nl/~ralf/JavaGI/)? I think it gives a sane new approach to static interfaces and mixin-like features, instead of just copying everything form Ruby.

Talkig about hashes, is not it already easy enough:

var hash = new Dictionary<string, string> {

{ "Color", "red" },

{ "Width", 15 }

}

?

Or do you really want tuples (guessing from the width value being of different type than color)? Then it would be

var tuple = new {

Color = "red",

Width  15

}

"Everything is virtual" is a hack, but I would vote for method interception.

Reshef Mann
11/26/2007 08:06 AM by
Reshef Mann

U forgot to mention dynamic interfaces and a boo lover like u should know... :-)

I understood that MS intended to include it in C# 3.0 but finally postponed it since it wasn't required for linq to work.

I would take dynamic interfaces over the awkward linq...

Ayende Rahien
11/26/2007 09:16 AM by
Ayende Rahien

Reshef,

What do you mean by dynamic interfaces?

Reshef Mann
11/26/2007 09:59 AM by
Reshef Mann

Say u have:

public class A{

public int Id {get; set;}

// More properties

...

}

public class B{

public int Id {get; set;}

//More properties

...

}

U can declare something like:

public dynamic interface IIdentifiable{

int Id {get; set;}

}

and in your code cast both class A and class B as IIdentifiable without having to actually implement IIdentifiable.

Resembles Boo's duck datatype, isn't it?

Frans Bouma
11/26/2007 10:36 AM by
Frans Bouma

I asked Anders about mixins and AOP at the last summit, and he made it pretty clear that AOP is something he truly dislikes and it's very likely it won't be added to the language.

This is sad, and also looking at what they added to the language, it's pretty funny because if they DID add AOP specific elements, they could have solved things properly instead of flaky as with extension methods (but not properties) etc.

Niki
11/26/2007 03:37 PM by
Niki

Am I the only one whom AOP reminds of Intercal's "COMEFROM" directive? I know there are certain things like logging or performance profiling that could be done in a very elegant way using AOP. But then I always imagine debugging a program that just jumps somewhere completely different with no apparent reason at the source of the jump. And that's not a weird side effect of AOP, it's the intended effect.

I am a huge fan of metaprogramming though, ever since I began to understand the true power of Lisp, but I doubt it will ever be included in C#. They could probably have implemented Linq with a few generic metaprogramming concepts, but they chose to hard-wire it in the compiler, so I guess the decision has already been made against any serious kind of metaprogramming.

IMO the best we could hope for is that someone comes up with a CLR-friendly (perferably compile-time-static-typed) metaprogramming language that integrates nicely with C# and all the other .NET languages.

Daniel
11/26/2007 04:07 PM by
Daniel

Niki,

Boo is a compile-time-static-typed CLR-friendly metaprogramming langauge and it works fine with C#, VB, etc.

http://boo.codehaus.org/

Niki
11/26/2007 05:02 PM by
Niki

Daniel,

I know Boo. It's a promising language, although metaprogramming in Boo is nowhere nearly as concise as macros in Lisp or Scheme. (But I don't know if that could be done in a language with a rich syntax like Boo.)

My main problem with Boo is that (AFAIK) it still doesn't naturally support .NET generics. Either that, or the documentation on this topic is hopelessly outdated.

Ayende Rahien
11/27/2007 12:42 AM by
Ayende Rahien

Reshef,

Duck typing should cover this. It looks like duck typing with strong typing, which doesn't really mix. I don't really like it, it looks awkward. And there isn't a good way to handle this in the CLR.

Ayende Rahien
11/27/2007 12:44 AM by
Ayende Rahien

Frans,

Tough for him.

I am with you on that, this is something that can be really helpful on the language level. That he doesn't like it is nice, but it doesn't change the fact that this is a desired featured.

To me, it looks like the need to dance around AOP is causing a lot of warts in the design of C#.

Ayende Rahien
11/27/2007 12:45 AM by
Ayende Rahien

Niki,

Go check boo, that is exactly what this is.

Ayende Rahien
11/27/2007 12:46 AM by
Ayende Rahien

Niki,

Check the recent stuff about DSL building, from quasi quotation to meta methods.

Yes, generics is still being added in, but it is possible to both consume and create generic types.

And yes, the docs are out of date.

Reshef Mann
11/27/2007 01:59 PM by
Reshef Mann

About dynamic interfaces,

I don't think that it is likely to see real duck typing from microsoft ever in C#.

And about handling it in the clr, can't it work like Boo handles duck typing or the way the DLR works?

Ayende Rahien
11/27/2007 02:38 PM by
Ayende Rahien

Reshef,

This is strictly something that the compiler has to do, it is not related to the platform.

Niki
11/28/2007 02:15 PM by
Niki

Thank you David and Ayande, I've had another look at boo, especially at the newer test cases, and you're right, that's exactly what I meant.

Guess I'll have a boo-power-weekend soon!

Comments have been closed on this topic.