Geeks With Blogs

News


www.flickr.com
This is a Flickr badge showing photos in a set called Bornholm with a DSLR. Make your own badge here.

Jannik Anker .NET developer blog

I just browsed through the C# 3.0 Language Specification, and noticed something horrific. They are planning to support implicit typing, meaning that the following could become valid code (outside of JavaScript ;-):
var test1 = 1;
var test2 = 1.0;
var test3 = "test";

The above code initialises an int, a double and a string... I fail to see how this is not a "downgrading" of C#. I mean, it bothers me that this way is the "only" way in JavaScript! Why introduce it in a "third"-generation programming language? And, as another curiousity, the initialisation must occur as above (immediately), so that var test; test = "test"; is invalid.

Why give people the option to further confuse their own code? If you don't know what a variable will end up containing (review your code), use an object type.

[Listening to: Feel Good Inc. - Gorillaz - Demon Days (03:43)]
Posted on Wednesday, September 28, 2005 1:15 PM C# | Back to top


Comments on this post: C# 3.0 - implicit typing ("var")

# re: C# 3.0 - implicit typing ("var")
Requesting Gravatar...
The "var" keyword doesnt downgrade C# at all... those variables are still very much type checked, if you tried to assign test3 = test1 you'd get a compiler error.

The only true problem for C# purists (zealots?) are that you dont directly see the type, but thats because of the newer anonymous types.

IMO its a good step forward towards unifying the Code to the Data.
Left by Eric Newton on Sep 28, 2005 5:22 PM

# re: C# 3.0 - implicit typing ("var")
Requesting Gravatar...
var in C# should not be confused with var in javascript or variant in VB.
Var is strongly typed and is recognized by the compiler.

typically:
var myc = new { Customer.Name, Customer.SSN };

myc.Name2 = "test"; // will give a compiler error

This will make more sense when IntelliSense starts working better with it too.
Of course, it makes a lot of sense when paired with LINQ.

/roger.
Left by Roger Larsen on Sep 28, 2005 7:09 PM

# re: C# 3.0 - implicit typing ("var")
Requesting Gravatar...
Yes, it's strongly typed, but I still don't see how this can be an improvement of the language.

Maybe, as Roger says, it'll make sense when paired with LINQ. However you should always be able to know what object type you are working with, and what type you are expecting to be returned from any kind of statement, including LINQ statements...

And that's all I'm saying - if you know that any kind of statement should return a string, why not define it as a string?

I don't get it...
Left by Jannik Anker on Sep 29, 2005 6:25 AM

# re: C# 3.0 - implicit typing ("var")
Requesting Gravatar...
Mark Rendle (dotnetjunkies.com/WebLog/mrendle/archive/2005/09/28/132971.aspx) agrees with me on this one, I believe ;-)
Left by Jannik Anker on Sep 29, 2005 12:58 PM

Your comment:
 (will show your gravatar)
 


Copyright © Jannik Anker | Powered by: GeeksWithBlogs.net | Join free