in

ASP.NET Weblogs

J e r o e n ' s   w e b l o g

Some thoughts on C# 2.0

It's the final day of TechEd Europe 2004 and even though I still have a couple of sessions to attend, I can say it's been a very interesting and fun week! Most of the sessions had some really cool content, although I personally would have liked to see a couple more advanced level sessions (or at least not have those that are held be planned in the same timeslots). This morning I went to Visual C# 2005: Language Enhancements, presented by Dan Fernandez, the Visual C# product manager. First of all I'd like to say that he's a very good speaker, the session was very quick-paced (mostly because there was so much ground to cover) but never confusing or unclear.

The most important thing and because of that discussed in the greatest detail were ofcourse generics. Because of their significance I had already read some articles about them (such as Jason Clark's two articles in MSDN magazine last year) so that contained little new information, especially since I've already been playing with them for the last couple of days with the Visual C# Express beta. Still, the part about constraining generic types was new to me, but besides that it was good to get another overview with live samples

Next was a discussion of anonymous methods which will fortunately end the relatively large amount of code needed to create simple eventhandlers, although one of the examples contained an entire inline method, about 10-15 lines of code, which would be a bad idea to actually use I think, because those things don't really make code more readable. Mostly because the idea of methods-within-methods are fairly unknown to programmers of other regular languages (C++/VB/Java), so that would make reading C# more difficult for non-C# developers.

Then there was a discussion of nullable types, iterators (of which the new yield concept made me think about co-routines), property accessors, static classes and fixed-size buffers, which all sound like great new additions, even the namespace alias qualifiers.

One thing didn't make me happy though, which is partial types. I really don't see the advantages in having them. For instance, you might say, it moves the generated Windows Forms and Web Forms clutter into another file so you don't have to deal with them in your main sourcefiles. Well, there's actually this cool #region feature the IDE supports that lets you collapse them. In fact, all the generated code (also for stuff like interface implementations) is always put into collapsed regions by default. However, I do often use some other editor when looking at other people's code or to quickly try to understand something in a class by opening it in some text-editor and searching for a methodname. No longer can you rely on finding it because it might reside in some other file which contains another part of the class you're looking through. How to figure out where all parts of a class actually are? By forcing some naming convention on files? That would be a step back (towards Java) so that doesn't sound like a good idea.

What I disliked the most is that the session demonstrated that the VC# IDE is totally capable of dealing with multiple files that contain a single class like they're all together in a single file, which means Microsoft has invested quite some time into developing this, even though it adds absolutely nothing on a functional level. But hey, if everybody wants it, I suppose I understand it would get implemented eventually. Personally, I think I'll stuff all the generated partial types into std_afx.cs, along with the new no-warning-policy-evasion mechanism with #pragma.

Published Jul 02 2004, 02:32 PM by jvdbos
Filed under: ,

Comments

 

joe said:

Have you ever tried writing your own code generation code, or extending a class which was generated elsewhere (such as a typed dataset)? Try that, then tell us you don't see the point of Partial classes.
July 2, 2004 9:40 AM
 

Wesner Moise said:

Actually partial types is a very enabling feature, it allows code-generated code (not just from the Windows forms designer) to be easily included into any class--without the need for specialized parsing of the source file and without possibly destroying user defined code.

Generated code results is associated with large-scale productivity improvements as well as reliable and consistent code.

Code generation techniques with abstract base classes have many limitations.
July 2, 2004 9:41 AM
 

Jeroen van den Bos said:

On the subject of partial types' use with code generation, I would say that if you want to extend generated code, why not just use inheritance for that?

Perhaps that's awkward if you already want to inherit from something else in a lot of scenarios, but then I'd rather have had that multiple inheritance was added to C#. You can ignore that as well, but at least it provides actual additional functionality over implementing partial types to the people that do want to use it.
July 2, 2004 10:45 AM
 

lechonsazo@hotmail.com said:

Partial types a slick feature, yes. Well-implemented in Whidbey Beta 1: no! Create a web forms project and add a web form. Go to the code behind page. Now ... here's the fun part ... *try* to find the generated portion of the partial type. Go on, I'll wait. Can't find it, huh? Because ...drumroll... it's hidden from the developer! What a smart idea! Give me no way to navigate to the other 60% of the code in the class I just defined!! Brilliant!!! So, this ought to make altering the inheritance hierarchy a snap. I thought Partial Types were supposed to make us *more* productive.
July 16, 2004 2:47 PM
 

lechonsazo@hotmail.com said:

Class view is completely useless in Whidbey. Page classes don't show up and functionality like add override has been stripped out.
July 16, 2004 2:52 PM

Leave a Comment

(required)  
(optional)
(required)  
Add