CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

What do you want in C# vNext?

I'm somewhat of the opinion that static typed languages are closing in on being an evolutionary dead end, but let's just say that C# is still important for the foreseeable future.  That being said, what do you want for C# vNext?  If we have to be constrained by static typing, I vote for making C# more like Objective C (not that I've ever coded in Obj C, just that it seems to have the things I want.).  My little list in order (not that I expect much of it to happen) is this:

  1. Mixin's. I found myself really wanting this for a framework I have in my current project.  Extension methods are okay, but I'd rather make it all the way to Mixin's.  Obj C can do it as a static typed language so it's definitely possible.  Heck, you can kind of do it in JavaScript.
  2. Symbols.  Reflection based solutions could be so much easier with Symbols.  I'd love to have compiler safe equivalents to Ruby Symbols.
  3. Make hashes a language feature.  I keep bumping into frameworks that really want to pass around hashtables.  If you absolutely have to do that, I wanna do var hash = :key => "red", :key2 => "green" in one line of code.  Somebody recently commented that object initializers might be a decent compromise.
  4. Automatic delegation ala Ruby or Objective C.
  5. Metaprogramming!  Method Missing magic!  I'm not holding my breathe on this one because it sounds like a bridge too far for me.  Give me metaprogramming and mixins and I think we can do AOP like things with less effort.
  6. Everything is virtual by default to make mocking easier

Anyway, what's your wish list?



Comments

Bob Grommes said:

The framework already has symbols.  It's called string interning.  The only fly in the ointment is that you can add to the interned strings list, but you can't delete from it.  However, for many purposes it's perfectly usable just the same.

bobondevelopment.com/.../optimize-memory-consumption-using-string-interning

I do agree that some syntax sugar would make string interning easier to use, though.

I don't think they're going to want break people's existing code by changing the default to virtual on methods.  But, I could see it being a compiler option that's off by default.

I'm with you 100% on mixins.  It's by far the most useful thing that multiple inheritance has to offer.  Presumably mixins could be implemented for significantly less effort than a full MI implementation.

# November 25, 2007 9:52 PM

Ayende @ Rahien said:

C# vNext

# November 25, 2007 9:55 PM

Sergio Pereira said:

#6 looks improbable.

One nice feature that came across my mind the other day would be a even better syntax for passing an anonymous delegate to a method. I'm specifically trying to get a similar syntax as in Ruby, where a block can be passed as the last argument to a method and the syntax looks oh so natural:

//C# 4 from a dream

Transaction.Scope() : with (trx)

{

  obj1.DoSomething();

  obj2.DoStuff();

  if(obj2.Failed) trx.RollBack();

} //commits by default.

File.Create("error.log") : with (f)

{

  f.WriteLine(someException.ToString());

  f.WriteLine("Error at {0:d}", DateTime.Now);

} //file will be released here

pdfDoc.CreatePage() : with (page1)

{

  page1.MarginSize = 2;

  //..more stuff...

  page1.CreateParagraph() : with (par)

  {

     par.Align = Align.Center;

     par.AppendText(" blah blah blah...");

   }

}

I got carried away, but I hope the idea makes sense.

# November 25, 2007 10:17 PM

DotNetKicks.com said:

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

# November 25, 2007 10:44 PM

Chad Myers' Blog said:

C# vNext, pause. VS vNext all-hands-on-deck

# November 25, 2007 10:45 PM

cmyers said:

@Sergio: Most of the things you describe are already available in C# with similar (and not much more) syntax.  The using(){} block would handle everything you show there except the automatic commit of the Transaction Scope. But you could easily make an IDisposable wrapper class for that (a la MockRepository.Record() in Rhino.Mocks).

# November 25, 2007 11:05 PM

Sam Smoot said:

@Bob:

Ruby's Symbols are interned Strings as well. The C method to get a Symbol is actually rb_intern() IIRC. They also suffer from the same drawbacks (they can't be removed once added to a process). Which is why you should use them with care.

A Symbol to represent a column or action name: Sure thing. A small finite set and nice performance gains.

A Symbol to represent a user-name: Bad idea. Basically an infinite set that will crowd the symbol table and drag down performance across the board as a result.

@Jeremy:

Heh... default-virtual. I've been saying that for years. :-)

# November 25, 2007 11:40 PM

Evan said:

Your list doesn't really sound like c# vnext.  It sounds more like Ruby.

And that's "on the way".. :-)

Evan

# November 26, 2007 1:09 AM

JH said:

Does this resolve mixins?

msdn2.microsoft.com/.../bb625996.aspx

# November 26, 2007 1:16 AM

Keith Hill said:

Compile-time metaprogramming ala languages like Converge (digg.com/.../446482).  Having the ability to define new syntactical constructs like you can with Lisp's defmacro could be very powerful and eliminate a lot of boilerplate code.

# November 26, 2007 1:51 AM

Andrey Shchekin said:

AOP is important, other things (like everything virtual or hashes) are out of place. Symbols seem dangerous, since they create an illusion of being compiler-checked.

# November 26, 2007 2:31 AM

John Rusk said:

What if symbols really were compiler-checked?  No illusion then :-)  <a href="dotnet.agilekiwi.com/.../symbols-part-3.html">This page</a> links to several ideas that I've either linked to or posted myself.  

As for mixins, here's one suggested way to do them, <a href="kirillosenkov.blogspot.com/.../john-rusk-on-extension-interfaces.html">extension interfaces</a>.

# November 26, 2007 3:22 AM

nick said:

Proper support for design by contract. You can only do this properly with support from the compiler, and it has to be a language issue.

That removes the need for a lot of unit testing.

The unit testing is better replaced with code analysis and automated unit testing.

# November 26, 2007 4:49 AM

Sergio Pereira said:

@cmyers

Oh, I knew that. But it's not the same thing as having syntax to support it. Furthermore, that would enable the disposable object to more easily enforce the disposal of any required resource, commit what needs to be committed, destroy scopes, etc. Think about the File.Create example above, the logic to properly dispose the file handle could be baked inside that File class for everyone to reuse if desired.

//File class

public static void Create(string path, FileBuilder theDelegate)

{

 using(StreamWriter file = new StreamWriter(path, false))

 {

   theDelegate( file );

 }

}

Another example, how many times we have written code to process a file line by line...

public static void EachLine(string path, FileLineProcessor theDelegate)

{

 using(StreamReader reader = new StreamReader(path))

 {

    string line = reader.ReadLine();

    while(line != null)

    {

       theDelegate( line );

       line = reader.ReadLine();

    }

 }

}

// usage:

List<string> commentBlocks = new List<string>();

File.EachLine("myclass.cs") : with (line)

{

 if(line.Contains("///")

    commentBlocks.Add( line );

}

I don't know ... To me it just seems like something that could add value to the language.

# November 26, 2007 9:05 AM

CV said:

C# yNext?  Microsoft quit changing things on us.  Give us a break so we can get some work done without learning all the new crap all the time.  It makes me cringe every time I hear about some new cool feature I will never use.  Please MS, stop the friendly fire!

# November 26, 2007 10:32 AM

Carlton said:

Agreed; stop changing things so much.

Curious why people think static languages are going the way of the dinosaur?

# November 26, 2007 11:40 AM

Shadi Mari said:

built-in design-by-contract support.

# November 26, 2007 12:27 PM

Sergio Pereira said:

@CV

C'mon. Are you're seriously complaining about evolution? The C# language team has been pretty good at not introducing breaking syntax changes.  You can elect not to learn the new stuff and continue writing using the 1.0 syntax if that makes you happy.

Or are you complaining about software development in general?

# November 26, 2007 12:34 PM

Chuggle said:

Everything virtual by default....oh yes please (crazy that it isnt like that already)

I'd like to be able to do something like

List<object> objectListHoldingStrings = new List<string>();

# November 26, 2007 1:14 PM

scarnie said:

Extensible compiler pipeline...

I want the ability to use (and build) custom attributes that will be executed during compilation.  An example today is the [Obsolete] attribute, which shows a compiler warning..

These custom attributes would derive from specific base classes to determine functionality.  A good example is to look at the functionality exposed by PostSharp.  Some features:

 * IL rewriting

 * Validation

 * AOP

Extensible compiler pipeline - a-la Boo

# November 26, 2007 1:21 PM

john said:

Jeremy, get a chance and look at the Nemerle (nemerle.org). It is already has a great metaprogramming subsystem. It is amazing!

# November 26, 2007 1:22 PM

Fredrik Normén said:

I want multiple return values like:

return 0, 1, 3;

var x,y,z = myFunction();

Ignore the second return value:

var x,,z = myFunction();

# November 26, 2007 1:25 PM

Ivan Porto Carrero said:

Mixins in c# 3.0

# November 26, 2007 1:51 PM

John Rusk said:

Opps.  Those links didn't come through properly.

The one about mixins is: kirillosenkov.blogspot.com/.../john-rusk-on-extension-interfaces.html

The one about symbols is: dotnet.agilekiwi.com/.../symbols-part-3.html

and also this discussion on MS's site covers symbols too: forums.microsoft.com/.../ShowPost.aspx

# November 26, 2007 2:07 PM

Mendelt Siebenga said:

Mixins could be implemented by extending generics so you could do generic inheritance like this:

class Mixin<T> : T {

 ...

}

Then you can use the mixin to extend a string like this:

Mixin<string> mixinString;

# November 26, 2007 3:15 PM

Patrick Smacchia said:

Definitly non-nullable type:

codebetter.com/.../i-want-non-nullable-types-in-c-4.aspx

Neat and dramatically helpful.

# November 26, 2007 3:32 PM

Mendelevium said:

Mixins in C#

# November 26, 2007 3:39 PM

James Curran said:

One thing I'd like to see, which I'd consider more of a bug-fix to v2 than a new feature for v3, is something which I've been calling a "contract".  It would essestially be an interface on steroids, and only used in generic contraints.  I would be like in interface, but could also specify other things that the class must implement/have available, such as static members, operators, and ctor parameters,

# November 26, 2007 3:47 PM

Luke Breuer said:

I agree with the above and add:

A) I'd like a way to specify that variables should be disposed of, within the current method, after they are last referenced (and in the relevant finally statements).  This should not be too hard, since the compiler knows the last time they were referenced (this is required for .NET garbage collection).  Unfortunately, this feature might break the "pit of success" goal for .NET.

B) Ability to refactor an anonymous type into a declared type.  This is not currently possible if one wishes to retain the named parameter approach over the constructor approach (new Foo() { Bar = 2 } vs. new Foo(2)) and get immutability.  There is no way to allow the former kind of assignment with readonly fields/properties (only the constructor has permission to write to them).

C) A possible alternative to B, and very useful in its own right: named parameters.  Calling a method and passing (true, true, false, true) is not readable at all, or as Scott Bellware would say, _soluble_.

D) Better type inference.  This is a hairy issue, to which anyone who has debugged Haskell type errors can attest.  However, I think excellent IDE support would mitigate this issue.  Being able to access anonymous types, strongly typed, outside of the method in which they were declared, would be quite helpful, especially for rapid, prototype work.  It should be possible to use refactoring tools to make types explicit if necessary.

@Jeremy Miller: your justification for making everything virtual by default is really a hack, IMHO.  Eric Lippert has an excellent blog post on why most of the .NET framework classes are sealed [1] that addresses this issue.  In short, unless your methods are designed to be overridden, you are making them virtual only for testing purposes and in doing so, someone can override them in a way for which you did not plan.  Eric Gunnerson also discusses this [2] and there is a decent amount of discussion in the comments.  Virtual by default is also a performance issue, which is one thing I think the Java HotSpot optimizer was built to overcome: figuring out which virtual methods are never overridden so that the vtable call can be elided.

[1] blogs.msdn.com/.../61803.aspx

[2] blogs.msdn.com/.../133570.aspx

@Chuggle: List<object> objectListHoldingStrings = new List<string>(); is tricky business.  C# allows you to do this with arrays in a very hacky, non C#-ish manner because Java allows it:

object[] objs = new string[1];

objs[0] = 2; // ArrayTypeMismatchException

There are a few options:

1) make the lvalue immutable: acceptable (List<object> becomes ReadOnlyCollection<object>)

2) copy the list: undesirable because, IMHO, it violates the principle of least surprise

3) allow contravariance with IEnumerable<T>, as it is immutable

# November 26, 2007 5:30 PM

BCS said:

there is a language that is much like what you seem to be asking for: The D Programming Language. Even If you don't want to use it, it would let you get your hands dirty with a language that has most of what you are asking for. 1, 3, 5 and 6 for sure, maybe 4 and I don't know what 2 is but it might have it.

http://www.digitalmars.com/D

# November 26, 2007 8:13 PM

BCS said:

a clarification: D has a type of mixins, if it's the type you are looking for is another matter.

# November 26, 2007 8:15 PM

Dejan Lekic said:

BCS, not just mixins, D actually has more/less everything mentioned in the article - some of those for years (already years passed, phewww).

Mr. Miller, so much for "static typed languages are closing in on being an evolutionary dead end" talk...

Kind regards

# November 26, 2007 9:16 PM

Chyld Medford said:

Mixin's rock!

# November 26, 2007 11:42 PM

Stuart Gtreen said:

Everytime I read your blog you come over as a complete moron...

# November 27, 2007 9:55 AM

John Jeffery said:

One feature I admire in Groovy is the "?." operator. As I understand it, it allows you to traverse objects but stop if one of the objects turns out to be null. For example the expression "foo.Bar.Baz" will throw a NullReferenceException if the "Bar" property happens to return null, but "foo.?Bar.?Baz" will return null when the first null is encountered.

# November 27, 2007 6:10 PM

Jimmy Bogard said:

Generic covariance and contravariance.  When you need it, you really really need it.

And doesn't virtual by default make it more difficult to abide by LSP?  Seems like that can be solved with products like TypeMock and techniques like "subclass and override".

# November 27, 2007 6:18 PM

Cameron Singe said:

I reckon more ruby like features as mention in the article, what I would really love is being able to pass a block into a conditional statements

for example

return error_msg if !person.isValid()

I would also love to see the allowed use ? for boolean statements and the unless keyword, although not the most critical features ever, they do make for more elegent code

# November 27, 2007 6:35 PM

Judah said:

I'd like to see design-by-contract concepts into C#.

This would clean up code significantly -- imagine something like a [NotNull] attribute on your params instead of writing a million different null arg checks.

It would result in a codebase with fewer bugs.

I'd also like to see more functional concepts in C#: Spec#'s research is promising and also could result in code with fewer bugs.

That's what I ultimately want. Metaprogramming and AOP is nice, but really what I want is fewer bugs in my code. I want language and runtime help with this. Design by contract is one such way to accomplish this.

# November 27, 2007 9:59 PM

Jon Skeet said:

@Sergio: There's no need for anything beyond C# 3 to make line handling easy.

I've already written a LineReader : IEnumerable<string> class (very simply - it's not like it took a brainwave to come up with it) where you pass in enough information to make a TextReader *at the right time*. That "right time" is when GetEnumerator() is called. You can then do:

(Apologies for spacing issues - nasty proportional font...)

foreach (string line in new LineReader(...))

{

}

The file will be closed at the end of the foreach.

*And* you can use it very nicely in LINQ:

var query = from log in Directory.GetFiles(logDirectory, "*.log")

   from line in new LineReader(log)

   let entry = new LogEntry(line)

   where entry.Type = EntryType.Error

   select entry.SourceIPAddress;

Bingo, you now know all the source IP addresses which encountered errors, across many log files, only ever loading a line at a time, with pretty much no fluff in the code to get there.

LINQ to Objects rocks, and people aren't making *nearly* enough fuss about it...

Jon

# November 29, 2007 3:49 AM

SirMike said:

Nothing, absolutely nothing. The C# syntax is being more complicated and complex. I would focus on extending .NET library instead of useless features in the language.

All the Linq stuff is very interesting at first glance but when one starts working with that, he realizes that it does only very simple things. Linq to SQL is just veeeery simple mechanism good for fetching data from Notrhwind database. When you want to use it with advanced logic (with stored procedures in DB) it becomes useless. Even Scott Guthrie wasn't able to help me and said something like "Sorry, it's impossible". ;) MS should work on that harder because it's a veeery long way in front of them to create a good ORM.

# November 29, 2007 7:41 AM

Jon Skeet said:

@SirMike: Don't make the mistake of thinking that LINQ=LINQ to SQL, or that LINQ to SQL is the only LINQ to databases provider.

For in-process stuff, a lot of what you can do in LINQ can certainly be done without LINQ - but LINQ makes it cleaner, more readable, and generally nicer.

Jon

# November 29, 2007 7:55 AM

Mike said:

"Nothing, absolutely nothing. The C# syntax is being more complicated and complex. I would focus on extending .NET library instead of useless features in the language."

It's inevitable to get replies like this it seems. If a feature is useless to you, don't use it. But why should we suffer under your incompetence by not having these features at all?

Also, since do we have to choose between language features and library development? Did not .NET 3.5 introduce both (new C#/VB compilers AND new namespaces such as System.Linq).

Please use brain before posting, kthx!

# November 30, 2007 7:14 AM

Mendelevium said:

Mixins in C#

# December 2, 2007 8:09 AM

» Daily Dose of Links - 20071205 Alvin Ashcraft’s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats. said:

Pingback from  &raquo; Daily Dose of Links - 20071205 Alvin Ashcraft&#8217;s Daily Geek Bits: Daily links plus random ramblings about development, gadgets and raising rugrats.

# December 5, 2007 10:08 AM

Kaveh Shahbazian said:

Microsoft must stop changing C# so much, so fast. Instead they should make a 3rd language mainstream, Something between F# and Scala. Sure I will use it. Because for me, I must hack the shortages in C# and some bad designed aspects of it. For example generics are so limited in C# that it is in many scenarios useless. I want higher order data types and higher order structure of data (like lisp) and higher order data structures.

It seems Scala is a good choice. But it is on JVM. And F# with a more polished syntax and a good support can be it for sure!

# December 25, 2007 5:57 PM

Jeremy D. Miller -- The Shade Tree Developer said:

A couple months ago I made a post called What do you want in C# vNext? that outlined what *I* wanted

# January 2, 2008 1:42 PM

John Rusk said:

Personally, I'd like to see automatic properties enhanced so that, while they would still generate the backing store, they would access it via programmer-defined methods.  Keeps the conciseness of the currrent automatic properties, but adds a lot more power: dotnet.agilekiwi.com/.../enhanced-automatic-properties.html

# February 24, 2008 12:29 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP