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.
- 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.
- Symbols - I am ambivelent on that one. Syntatic sugar is important, but I have other things that I would value more.
- Make hashes a language feature - I think that you can do it right now with this syntax:
- Automatic delegation ala Ruby or Objective C - Um, isn't this just mixin?
- 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.
- 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.
var hash = new Hash( Color => "red", Width => 15 );
My own request covers:
- memberinfo() - the CLR already has this concept, so we just need the syntax for it.
- 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.
- 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.
- 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
Does this resolve mixins ? http://msdn2.microsoft.com/en-us/vcsharp/bb625996.aspx
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> {
}
?
Or do you really want tuples (guessing from the width value being of different type than color)? Then it would be
var tuple = new {
}
"Everything is virtual" is a hack, but I would vote for method interception.
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...
Reshef,
What do you mean by dynamic interfaces?
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?
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.
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.
Niki,
Boo is a compile-time-static-typed CLR-friendly metaprogramming langauge and it works fine with C#, VB, etc.
http://boo.codehaus.org/
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.
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.
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#.
Niki,
Go check boo, that is exactly what this is.
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.
Here's a discussion in the Microsoft forum on symbols/memberinfo:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=466000&SiteID=1&mode=1
Here's a discussion in the Microsoft forum on symbols/memberinfo:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=466000&SiteID=1&mode=1
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?
Reshef,
This is strictly something that the compiler has to do, it is not related to the platform.
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!
Comment preview