The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Short list of non-obvious things determined from the C# 2.0 draft

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frans Bouma

Posts: 265
Nickname: fbouma
Registered: Aug, 2003

Frans Bouma is a senior software engineer for Solutions Design
Short list of non-obvious things determined from the C# 2.0 draft Posted: Oct 25, 2003 6:26 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Frans Bouma.
Original Post: Short list of non-obvious things determined from the C# 2.0 draft
Feed Title: Frans Bouma's blog
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/fbouma/Rss.aspx
Feed Description: Generator.CreateCoolTool();
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Frans Bouma
Latest Posts From Frans Bouma's blog

Advertisement

A short list of things I could determine from the C# 2.0 draft which was released yesterday which are not a topic of much discussions but are good to know. I've added page numbers to the items, so you can go back to the C# 2.0 draft yourself and look them up (page numbers are the actual page numbers on the page). I've skipped the features: Generics, Anonymous methods, Iterators and Partial types, because these are the obvious items discussed in the draft :)

  • No support for multiple similar overloads with different returnvalues (Page 18)
    Sometimes you want to specify different overloads which have the same method declaration (method signature) but differ only in return type. There was speculation that support for this would be added to C# (Eiffel has it). However on Page 18, an example shows us that it will not be added:
    class G1<U>
    {
    	long F1(U u);	// Invalid overload, G<int> would have two
    	int F1(int i);    	// members with the same signature
    	// ...
    }
  • Support for Nullable types (Page 27)
    A very nice thing that will be added to .NET is the support for Nullable types. In .NET 1.1, you can't use an int variable in a situation where you want it to be null as well. You could use SqlTypes.* but these are not serializable. LuKa has programmed Nullable types for .NET, but that requires that someone using your code includes a reference to that library. A native FCL version of Nullable types is a welcome addition.
  • Type inference reduces typing, increases complexity for the reader (Page 30)
    Type inference is the mechanism the compiler will use to determine which constructed type to use by looking at the type of the parameters passed in. Example:
    class Util
    {
    	static Random rand = new Random();
    	static public T Choose<T>(T first, T second) {
    		return (rand.Next(2) == 0)? first: second;
    	}
    }
    will result in different types in the method when called using different types:
    int i = Util.Choose(5, 213);		// Calls Choose<int>
    string s = Util.Choose("foo", "bar");		// Calls Choose<string>
    
    While this saves the developer some typing, it is less readable code, IMHO, because when used with parameters, it is harder to determine by simply reading the code which constructed type the method will have.
  • Properties, events, indexers or operators may not be generic (Page 32)
    This may be a big item for some people and I fail to see why indexers and properties aren't among the elements which can be made generic. Especially properties and Indexers are extremely important for generic collections. But perhaps I'm mistaken and I didn't read the draft correctly.
  • Partial types must be compiled together (Page 70)
    I quote: "All parts of a partial type must be compiled together such that the parts can be merged at compile-time. Partial types specifically do not allow already compiled types to be extended.". It is understandable from a compiler's POV, it can be confusing perhaps when starting with Partial Types. Partial Types are extremely useful for code generators, and I can't wait to implement them :) The only fear I have is that Partial Types will not be part of VB.NET, so code generators which target multiple .NET languages are not helped by it in some cases. However I read somewhere that ASP.NET 2.0 uses partial types so VB.NET should support them as well.

I haven't looked deeply into iterators and anonymous methods yet, plus I'm sure I've overlooked some non-obvious gems so when you have any extra info, post them in the comments :)

Read: Short list of non-obvious things determined from the C# 2.0 draft

Topic: It Came From Beneath the Sea Previous Topic   Next Topic Topic: Ready or Not, Here Comes the CLR

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use