« Previous entry | Next entry » Browse > Snippets
Skip to comments (143)
[C#] New language features in C# 3.0
Posted by Niek on Mar 07 2006 @ 21:37 :: 31777 unique visits
C# 2.0 is just out (check Matthijs' earlier posts [1] [2]) and Microsoft is already working hard on the next version of C#, version 3.0.In this post, I'll describe some new (and cool!) language features that will be introduced in this version. Please note that the resulting binaries will be backwards compatible with .NET 2.0, so C# 3.0 is only new on the compiler side.
The "var" keyword
This is a new and handy keyword that'll save you some typing. Example below:
CODE: CSHARP
// C# 2.0 behavior
int i = 10;
string s = "Hello codepost visitors!";
// New C# 3.0 var type
var i = 5;
var s = "Hello again!";
int i = 10;
string s = "Hello codepost visitors!";
// New C# 3.0 var type
var i = 5;
var s = "Hello again!";
The var keyword is NOT a completely new type, instead the compiler just takes a look at the right-hand side of the expression. If the right-hand side is an int, for example, the compiler will "replace" the var keyword with int. This means that the following contruction will NOT work:
CODE: CSHARP
// Will not work, 'cause the right-hand side of the var is unknown
var b;
b = 1337;
var b;
b = 1337;
Object initializers
In C# 3.0 there is also a new way to initialize objects. See example below:
CODE: CSHARP
This will also save some lines of code :)
Anonymous types
Another new feature is anonymous types. The syntax is as follows:
CODE: CSHARP
The compiler will create an anonymous class "under the hood". This class will have 3 private attributes (_name, _gender and _active) and 3 public properties with their respective getters and setters (Name, Gender and Active). This is especially handy when you're receiving data (from a file or via a network) and you don't want to create a class just to hold the data.
Extension methods
Another cool thing is that you're able to add (static) methods to existing (default) classes. As an example, here is the code to add a ToMD5() method to the string class:
CODE: CSHARP
public static class StringExtensions
{
public static string ToMD5(this string s)
{
System.Security.Cryptography.MD5 md5;
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(s));
// Return the result, replace unneeded "-"
return System.BitConverter.ToString(result).Replace("-", string.Empty);
}
}
{
public static string ToMD5(this string s)
{
System.Security.Cryptography.MD5 md5;
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(s));
// Return the result, replace unneeded "-"
return System.BitConverter.ToString(result).Replace("-", string.Empty);
}
}
Once compiled, all string objects now have the ToMD5 method. If you placed the extension class above in a seperate namespace, you should import this namespace to enable the usage. Example below:
CODE: CSHARP
string s = "Hello, this string is gonna be MD5-ed!";
Console.WriteLine(s.ToMD5()); // Prints the MD5 hash
Console.WriteLine(s.ToMD5()); // Prints the MD5 hash
LINQ
LINQ stands for Language Integrated Queries and is maybe the biggest enhancement in C# 3.0. Because this is such a huge topic, I'll discuss this in a seperate post (to be posted in a few days). Stay tuned :)
143 comments posted so far
Add your own »
2. On Mar 08 2006 @ 20:19 guest wrote:
That's nothing. I used VB 3.0.3. On Mar 08 2006 @ 20:19 guest wrote:
The var keyword is a really different concept respect the VB variant type. It is not a generic container but instead a way of making a variable with a strong type decided at the moment of the construction by assignment.4. On Mar 08 2006 @ 20:19 guest wrote:
no crap. when is c# 3 slated to become the standard, anyhow?5. On Mar 08 2006 @ 20:20 guest wrote:
There is a reason why many people like C#, it's not VB. Why take a nice language and make it VB'ish? If that's the route they choose to go I might make a perminate switch to java.6. On Mar 08 2006 @ 20:21 guest wrote:
var keyword = why?, is the question that i would ask...are we moving towards a weakly-typed language here?Object initializers = use constructors maybe? i don't get why these initializers are necessary or helpful.
Anonymous types = see var keyword
Extension methods = what the hell? what happened to encapsulation???
IMHO, none of these features are necessary as long as your design is sound...
7. On Mar 08 2006 @ 20:22 guest wrote:
var keyword... and this is useful how? Some of the other features seem handy, but this one I'm not so sure about.8. On Mar 08 2006 @ 20:24 guest wrote:
I think the var stuff is a waste of time. C'mon, who doesn't know the type of their object when they are creating it. All this will do is make your code harder to read by other coders. Var leads to sloppy code.I look forward to the object initializers and the extension methods. These look promising and can definately promote readability and reduce lines.
9. On Mar 08 2006 @ 20:26 guest wrote:
You guys are missing the point of the var keyword - as the compiler will automatically pick the most appropriate type you can do things like:for(var i=0;i<5;i++) { ... }
and
for(var i=0;i<50000000000;i++) { ... }
and not have to care if it's an int32 or int64 or whatever.
10. On Mar 08 2006 @ 20:26 guest wrote:
Use it or don't use it, it's still strongly typed.11. On Mar 08 2006 @ 20:29 guest wrote:
for(var i=0;i<5;i++) { ... }and
for(var i=0;i<50000000000;i++) { ... }
you don't think it's helpful for the programmer to know the type of the variables he's playing with? What if something in the {...} depends on the type of index????
12. On Mar 08 2006 @ 20:29 guest wrote:
> IMHO, none of these features are necessary as long as your design is soundIMHO, let the developers decide what are sound and what are not. No one forces you to use these features, so you can be as sound as you are right now.
13. On Mar 08 2006 @ 20:30 DougDante wrote:
You missed LINQ => Language Integrated Query. I've seen it demoed, and I can try to explain it.Basically, SQL databases, XML docuemnts / ANYTHING can use anonymous methods and the same syntax to do SQL-like queries:
var Result = select Name, Address from MyCustmers where MyCustomers.zip == 10001;
This makes a list of things with an anonymous class with two membmers, Name and Address.
Should also work for XML documents, etc.
14. On Mar 08 2006 @ 20:33 guest wrote:
I like the object initializers but couldnt you cut down on even more code by implementing a constructor that takes those items as arguments? then you wouldnt have to type "Name=" etc. etc. thats kind of the purpose of constructors with different kinds of arguments.I dont think i get the extention methods... i mean I get what they are for and i can see the use... but the syntax escapes me. seems like you can get yourself into some interesting trouble with this one... :)
the var thing seems laim, its a typed language why not enforce it? does it dynamically change the type?
EX: (perl-like behavior)
CODE: CSHARP
var a = 123;
...
a = "i am now a string!"
...
a = "i am now a string!"
15. On Mar 08 2006 @ 20:35 guest wrote:
The thing that isn't mentioned in this post is that these features were all added to facilitate LINQ. Go watch some of the PDC sessions concerning LINQ and you will understand much better.Please, just because this is a Microsoft technology, don't dismiss it out of hand.
var is determined at compile time, not run time. It is no slower than int or string.
16. On Mar 08 2006 @ 20:36 guest wrote:
var should not be confused with VB6 variant or with dynamic languages runtime variable assignment. It uses type inference at compile time which makes it as fast as the full declaration. It basically allows us to do the shortcut:var CustomerOrders = new Dictionary<Customer, List<Orders>>();
Instead of:
Dictionary<Customer, List<Orders>> CustomerOrders = new Dictionary<Customer, List<Orders>>();
17. On Mar 08 2006 @ 20:36 guest wrote:
I would like to point out that the author EXPLICITLY STATES that the "var" keyword is to SAVE KEYSTROKES. I would now like to thank Microsoft for saving me from the horrible fate of WASTING KEYSTROKES which we all know are in SHORT SUPPLY! The author points out that we can all save a WHOPPING THREE KEYSTROKES with this new feature! Oh boy! I'm sure MSFT is going to go through the roof now!18. On Mar 08 2006 @ 20:36 guest wrote:
"and not have to care if it's an int32 or int64 or whatever"I saw nothing in this article that suggests the compiler will take a look at the entire for() loop to determine the type. All it's going to do is look at the initializer, which in your example is 0 in both cases. So the variable will wind up being the same type in both cases.
If the type is large enough to store "50000000000" in the second case, then it's wasting space in the first. Conversely, if it's sized smaller in the first case, it's too small for the second case (resulting in a run-time error...or possibly a compile-time error if the compiler tries to convert "50000000000" to the same type as "i").
I'm in agreement that the "var" doesn't seem to add anything. All it appears to do is to allow the programmer to not know the type name for a given kind of data. The type still needs to be known at the point of the declaration, and frankly allowing the programmer to not actually know the type seems like a bad idea to me (since the actual type will affect the usage of the variable elsewhere in the code, as someone else pointed out).
19. On Mar 08 2006 @ 20:38 guest wrote:
The first 3 features smell like PHP or Ruby.20. On Mar 08 2006 @ 20:39 guest wrote:
the problem with var is not the type safety but the readability as a previous poster mentioned. and what does it save you? typing "int" is just as fast as typing "var"! :-) And with autocomplete these days typing long names is just as easy.The posted needs to make the last bit about LINQ stand out...i think a bunch of us missed it...
21. On Mar 08 2006 @ 20:44 guest wrote:
Boo (http://boo.codehaus.org) has most of these features already!Statically Typed, Extension Methods, Type Inference, lambda functions, etc
But also has built-in support for Arrays,Lists,Regular Expressions,Templating, etc. Oh well maybe the rest will come in C#4
22. On Mar 08 2006 @ 20:44 guest wrote:
Does anyone have a MS reference for these changes? I wouldn't get too worried until I saw an official document.23. On Mar 08 2006 @ 20:46 guest wrote:
Anonymous types seem like an elaborate scheme to get dictionary-like behaviour. I do like the shortcut for instantiating objects.I think a lot of these seem like ways to make C# a little more like the rest of the modern languages we have. That could be good, or bad depending on how they go about it.
24. On Mar 08 2006 @ 20:48 guest wrote:
Aside fromvar o = new { Name = "Niek", Gender = "Male", Active = true };
I see no use for the var keyword
it encourages lazy programming and will be abused by people new to programming
This is like VB6 all over again, no matter if it's strongly typed or not.
New users will simply be ignorant to the importance of types.
Not to mention the fact that it makes debugging a whole lot more difficult
25. On Mar 08 2006 @ 20:51 guest wrote:
Well, C# is now heading in the same direction as C++, that is, the direction of adding gobs of features, which just makes a huge morass out of the language.As far as the
for(var i=0;i<5;i++) { ... }/for(var i=0;i<50000000000;i++) { ... } examples are concerned, the type of var is set in the declaration. "var i = 0" doesn't have any information leading the compiler to substitute int64; zero fits nicely in a smaller int type. The "i<50000000000" clause is not the declaration of i, it is a separate expression used in loop control. As such, it will not be used to determine the type of i. The for(var i=0;i<50000000000;i++) { ... } will likely fail at runtime with i exceeding the bounds of its integer type.
And to whoever said they used VB3.0: n00b. I used VB 1. Under Windows 3.0. To interface with Dialogic telephony hardware. It was UAE central.
26. On Mar 08 2006 @ 20:52 guest wrote:
Guest wrote:"You guys are missing the point of the var keyword - as the compiler will automatically pick the most appropriate type you can do things like:
for(var i=0;i<5;i++) { ... }
and
for(var i=0;i<50000000000;i++) { ... }
and not have to care if it's an int32 or int64 or whatever."
Are you sure about that? All the examples show are doing type inference from the initialization of the variable. What you're talking about is a good bit more difficult and requires looking at the whole function, and it's not clear to me whether C# 3.0 will go that far.
27. On Mar 08 2006 @ 20:52 guest wrote:
you guys don't seem to grasp the interest of the var keyword, so let me give you a small analogy: The variable type is infered at compile time, just like C++ templates without the convoluted syntax. You could easily write generic bits of code and just make a specialised class by inheritage.Maybe there are already other language constructs that take care of this in C#, I don't know. But this seems very handy anyway, IMHO.
28. On Mar 08 2006 @ 20:54 guest wrote:
I think the "var" keyword makes a ton of sense. There is no need to have a type before a variable name when you define the value immediately afterwards. The keystroke argument is also valid. Instead of assuming you are replacing "int" or "string", imagine getting rid of "MyExtremelyVerboseVariableNameInCamelCase", which are rather popular within C# code. When people put whole sentences for a classname, getting to omit it once saves keystrokes and errors.29. On Mar 08 2006 @ 20:54 guest wrote:
The var keyword is a way of implementing Python's dynamic, strong typing. It's a very good idea, and not prone to any of the pitfalls of VB's Variant.--
LeoPetr
30. On Mar 08 2006 @ 20:55 guest wrote:
Ruby has all these features since... eh... since it was designed?31. On Mar 08 2006 @ 20:56 guest wrote:
Using "var" saves keystrokes but it is really a neccessity when using anonymous types. Consider:var rec = new {Name = "Test", Age = 26};
Notice that you cannot replace the "var" with the name of the type, BECAUSE IT DOES NOT HAVE A NAME (it is Anonymous). This becomes quite important when using LINQ.
Bear in mind that type names can become quite long when using generics. Type inference has been standard in functional languages for ages and although the C# 3 type inference is rather primitive it is useful nonetheless.
32. On Mar 08 2006 @ 20:59 guest wrote:
What about:ISomeInterface xyz = new ConcreteObject();
this is quite common, no? (and good programming practice anyway). are we just gonna replace it with:
var xyz = new ConcreteObject();
and guess at the methods we can call?
33. On Mar 08 2006 @ 20:59 stevex wrote:
The point of var is to help make code that uses generics easier to follow.For example:
Hashtable<int, string> MyFunc();
...
var foo = MyFunc();
is easier to read than
Hashtable<int, string> foo = MyFunc();
If you really need to know what MyFunc returns the IDE makes it easy enough to find out. You should get proper IntelliSense for foo (because the IDE knows it's really a Hastable<int, string>.
Easier to read code, and less typing. Sounds good to me.
34. On Mar 08 2006 @ 21:01 guest wrote:
Guys, var is intended for use with features like the anonymous classes they mention.If we did not have var, we could not do this:
var o = new { Name = "Niek", Gender = "Male", Active = true };
If you said object o = new... whatever, you wouldn't have a type to downcast to, and therefore couldn't access the properties (since Name, Gender, and Active are not properties of object.)
And why would we want to do this? Well, I don't know much about LINQ, but I would presume the result sets would use anonymous types. I know if I were writing an ad hoc query engine of some sort, anonymous types could be really nice.
Its not about saving you typing.
Yes, it can be abused. Personally, I would prefer that var was only available for anonymous types.
35. On Mar 08 2006 @ 21:06 guest wrote:
> var foo = MyFunc();> is easier to read than
> Hashtable<int, string> foo = MyFunc();
var foo = MyFunc(); tells you nothing about the type of foo whereas Hashtable<int, string> foo = MyFunc(); tells you exactly what you are dealing with. It may not be pleasant on the eyes but the second version actually saves you time of having to check intellisense or whatever other IDE feature to get what foo is all about...
36. On Mar 08 2006 @ 21:07 PhilC wrote:
"var" keyword.... yeah. Easier to type than int. Not. Plus it makes a strongly typed language less readable as such."Extension methods".... Inheritance, anyone? Now there's no way of knowing for sure what extra functionality a class has just by looking at its name.
37. On Mar 08 2006 @ 21:07 guest wrote:
"are we moving towards a weakly-typed language here?"Nope, C# will be as strongly typed as before. If you don't believe so, you don't understand the var type. The var type is designed to not imply weak typing. As #32 and #35 says above, the var type is intended for use in combination with other new language features. It's no coincidence var appears in C# 3.0 as opposed to C# 2.0 that didn't have those.
38. On Mar 08 2006 @ 21:08 guest wrote:
""var" keyword.... yeah. Easier to type than int. Not."No one claimed this.
39. On Mar 08 2006 @ 21:09 guest wrote:
It's strange to see that c#, a somehow clone of Java, introduces weakly typed concepted and Java is doing the opposite path. Still, i think it will atract VB programmers and programmers from many interpreted languages.I've always watched C# as a bazzar of features from several languages and the "var" keyword is strengthening that.
About the extension methods, maybe i'm not seeing the full potencial of it, but i think it's a huge step backward in consistency and coherence.
You will start to see code like: "aString.makeCoffee()", "aString.sayHello()", etc...
It isn't good to see core classes with methods that dont appear on the API or anywere else.
40. On Mar 08 2006 @ 21:09 Pandaman wrote:
For those not familiar with C#, var could be a problem trying to figure out the actual type of the declared variable.Else
var is just a time saving feature.
41. On Mar 08 2006 @ 21:11 guest wrote:
I think many of you are missing the point of var. It's a necessity when dealing with LINQ. Also, using var does NOT take away from strong typing. You must assign the variable inline and you cannot change the type afterwards.42. On Mar 08 2006 @ 21:14 guest wrote:
I'm indifferent to var.Here's a silly justification for it. It aligns variables.
float a=1.2f;
int b=3;
string c="wicked awesome";
Geez, how ugly.
var a=1.2f;
var b=3;
var c="wicked awesome";
Now ain't that just lovely.
43. On Mar 08 2006 @ 21:19 guest wrote:
> You missed LINQ => Language Integrated Query.> I've seen it demoed, and I can try to explain it.
It basically does what you've been able to do with Foxpro et al since time immemorial, i.e. remove yourself from all the bullshit associated with working with data, and just work with the data.
44. On Mar 08 2006 @ 21:19 guest wrote:
why use var when you can just make everything a string :)45. On Mar 08 2006 @ 21:28 guest wrote:
If you think "var" is bad...wait'l you see LINQ!! It's gotta be the AWFULLEST syntax in a modern language (especailly in the "C" based environment) I've EVER seen! Microsoft has always been good at adding features that they CAN...instead of whether-or-not they SHOULD. The whole reason they "started from scratch" with DOT NET was they finally realized they had tackedo n SO many "creeping features" into VB, they had gotten away from a "Rapid Application Development Environment" due to adding complexity over all these years.46. On Mar 08 2006 @ 21:28 guest wrote:
var type sucks....47. On Mar 08 2006 @ 21:29 guest wrote:
In sharpdevelop, you can write:? i = 5;
? str = "The new var syntax is stupid.";
? thingy = new Foo();
and it will change the question mark to the desired type WHEN YOU COMPLETE THE LINE, giving you ample time to fix its mistakes if it makes them. This var thing will bite you in the ass, I guarantee it. If you want dynamic types, go to python or boo. Or a language with proper type inference from the ground up, such as ML.
xoxoxo
Jonathan
48. On Mar 08 2006 @ 21:30 Joe wrote:
The example given in the article for var is a bad example. It does deomnstrate what can be done but it doesn't demonstrate the why. In fact, you probably shouldn't use var at all if you know the type a priori. It does help with generics, but you can always alias them (using SpecialList = System...List<Special>;)For anonymous classes or the aforementioned LINQ it becomes necessary to use var. The benefits LINQ brings will completely outwiegh the confusion that var introduces.
49. On Mar 08 2006 @ 21:32 guest wrote:
'var' is all well and good until you're in a code review. IntelliSense doesn't work with paper yet.50. On Mar 08 2006 @ 21:35 guest wrote:
OK, so the Object Initializers is sorta like named, optional parameters. Why not just add that? It would eliminate a lot of method overloading!51. On Mar 08 2006 @ 21:40 guest wrote:
I think I'll sticky with perl52. On Mar 08 2006 @ 21:42 guest wrote:
Linq example on MS site:public void Linq1() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var lowNums =
from n in numbers
where n < 5
select n;
Console.WriteLine("Numbers < 5:");
foreach (var x in lowNums) {
Console.WriteLine(x);
}
}
My question. What was wrong with this:
public void NoLinq() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
Console.WriteLine("Numbers < 5:");
for (int i = 0; i<numbers.length;i++) {
Console.WriteLine(numbers);
}
}
looks like less typing to me...hehe :)
53. On Mar 08 2006 @ 21:43 guest wrote:
""var" keyword.... yeah. Easier to type than int. Not. Plus it makes a strongly typed language less readable as such."Extension methods".... Inheritance, anyone? Now there's no way of knowing for sure what extra functionality a class has just by looking at its name."
Hope you don't mind me saying, but you are a dumbass.
Nobody is saying var is easier to type than int, that's not the point of the keyword. var was designed to be used with LINQ.
And about your second paragraph... wtf?
1) You cannot inherit from string
2) Even if you did inherit from string the function still wouldn't be a member of the string class, it would be a member of the new class you made.
54. On Mar 08 2006 @ 21:44 guest wrote:
Can you data type the var statement like you can in Actionscript? Then it's not quite so weak.55. On Mar 08 2006 @ 21:50 guest wrote:
#53...do you think String.makeCoffee() is logical as a poster noted earlier? the string class was marked SEALED for a reason!btw...don't call people names...it makes you look stupid..
56. On Mar 08 2006 @ 21:53 guest wrote:
oh boy, can C# get any more gay then this? stop copying other peoples work and start bringing some new stuff innovative stuff to the table. This has perl, ruby and php written all over it, only with the bad taste of VB. So you managed to even suck at implementing 'inspired' concepts.Use a real language people, whatever perspectives C# seemed to have at first are quite washing away now. Heck I even want to thank you for the var concept, might bring some sense into people thinking about trying .NET:)
57. On Mar 08 2006 @ 21:56 guest wrote:
If they make this change to var I'm soo going back to JAVA.58. On Mar 08 2006 @ 21:57 guest wrote:
Glad to see someone isn't afraid to make a language more convenient (take a hint)59. On Mar 08 2006 @ 22:03 MikeOwens wrote:
It's sad to see many developers here confusing (strong vs. weak) and (static vs. dynamic) typing.I'm not a C# developer, but it is obvious to me that 'var' in C# is accomplishing the exact same thing as the soon-to-be-reintroduced C++ keyword 'auto'. It's basically adding type inference to a statically+strongly typed language.
Those claiming that it'll allow "sloppy code" or that it "weakens" the type system betray their own ignorance of modern type systems. This has been successfully used in Boo, Haskell, and soon, C++. All of which are statically and strongly typed languages. It basically tries to take some of the sting out of not using a dynamically-typed language.
The similar facility in C++0x would be:
CODE: CPP
// old
std::vector<int>::const_iterator it = somecol.begin();
// new, with inference
auto it = somecol.begin();
std::vector<int>::const_iterator it = somecol.begin();
// new, with inference
auto it = somecol.begin();
Neither "var" nor "auto" weaken the static and/or strong type system. They provide more than a shorthand, by adding another level of abstraction (consider changing the type of "somecol" above from an array to a linked list; you wouldn't be required to fix dozens of type declaractions.)
I rarely use Microsoft-specific programming environments, but I'm glad they have people in charge not swayed by some of the easily-spooked programmers above. Guarding the developer from genuinely useful features which some textbook programmers "won't get" is what makes Java a less interesting language than C#.
- Mike A. Owens
60. On Mar 08 2006 @ 22:04 guest wrote:
The extension methods are a copy of Objective-C categories. They are really useful for adding methods to large code base (frameworks) without extending the class. You do not touch encapsulation because you don't have access to class members. http://en.wikipedia.org/wiki/Objective-C#Categories61. On Mar 08 2006 @ 22:04 dannyy wrote:
Come on! Half of the comments so far were left by morons. Have you guys ever learned an aged concept called "type inference"? The whole point of "var" is not to introduce a VB-like syntax, but to introduce type inference to make your code simpler, and even more portable. Go back to read the article again, and read comment #9.62. On Mar 08 2006 @ 22:05 guest wrote:
WOW - everyone is crapping on the var. Granted the int / string example is rubish, but heck think of the power of using it to reference anonymous types. It's a slick powerful keyword for handling references to dynamic objects, and is completely inspired by dynamic languages (python, ruby, etc.). Other than sharing the same name as the VB keyword, they are completely different concepts.Take a look at linq, understand dynamic languages, really get a feel for generators and the like, and then you may have an idea where something like this: var o = new { Name = "Niek", Gender = "Male", Active = true }; can truly come in handy.
Many of these features are purely provided to make .NET more script / dynamic language friendly - and as proponents of those languages always say - "make you more productive"
63. On Mar 08 2006 @ 22:10 guest wrote:
not happy with auto either #59...level of abstraction?????? are you serious?READABILITY
and if you're too lazy to type, look at #47
64. On Mar 08 2006 @ 22:11 ILVC wrote:
Property initialization with a single initialization. Great!Var keyword... just fine.
Adding static methods to default classes..... Smalltalk did it better..
If there was a really efficient VM tu rule them all.... *sigh*
(not parrot please!)
65. On Mar 08 2006 @ 22:13 wezzy wrote:
Uh for me it looks very similar to Javascript. anyone else feel the same ?66. On Mar 08 2006 @ 22:15 u84six wrote:
var myNum = 30, myStr = "thirty", myLong = -30000000000000, myFloat = 30.03, amIThirty = false;67. On Mar 08 2006 @ 22:16 drawkcom wrote:
All of these features are in AS2/AS3 as well. There is an RIA battle brewing and with Avalon vs Flex 2 these were added I am sure to make that transition easier for people coming from AS2/AS3 to C# Avalon. The whole reason C# is areound was to lure the Java programmers over like me. This is another outreach. I wouldn't use these much but it may be useful to make a mini C# scripting engine alot easier for a deep app. Even engines like Unreal do this and a script in C# type would be very cool and useful. Its being used already but it woudl be even easier this way.68. On Mar 08 2006 @ 22:19 MikeOwens wrote:
Please stop confusing "repeating yourself at every opportunity" with either readabilty or safety.- Mike A. Owens
69. On Mar 08 2006 @ 22:20 guest wrote:
uhhh... Pain. Just go install cygwin on your windows box and start to learn the beuty if a unix command line. Then realize that whatever you throw together inside of cygwin can easily become a windows app or a linux app and become one with the entity that is GNU. Remember GNUs not unix, that is all there is to it.70. On Mar 08 2006 @ 22:32 u84six wrote:
The problems with Java far outweigh this added initializer convenience. I will never go back to Java no matter how much they pay me. "Write once, run everywhere". Yeah, nice try. Even c# apps run better on Linux than Java. lol71. On Mar 08 2006 @ 22:33 guest wrote:
#68/MikeCan you tell me the type of foo in this piece of code and tell me whether it compiles:
var foo = bar();
var foo2 = bar2();
foo.func();
int x = foo + foo2;
Yes, i understand that you can look up the return values of bar/bar2 and know the types but just looking at the code you cannot...
btw...i think everyone gets that this is type-safe and that foo.func() will not compile if the foo object doesn't support the func method. everyone can stop beating the dead horse...var = type-safe...
72. On Mar 08 2006 @ 22:34 u84six wrote:
Rule #1: Never initialize a variable with a return value. It's bad programming practice.73. On Mar 08 2006 @ 22:41 guest wrote:
Just trying to clarify confusion about the 'var' keyword. As already said it is strongly typed, inferred at compile time. Its primary purpose is support for anonymous types, and NOT for saving keystrokes. This is neccesary because of the LINQ query system. Take the example from a previous post:var Result = select Name, Address from MyCustmers where MyCustomers.zip == 10001;
The Result variable would be an anonymous type: probably a list container storing another anonymous type with these properties: String Name, String Adress. These is truly a neat encapsulation, and is very far from VB6 obscurity as I recall it.
One note about the extensional system:
Notice that the methods added are not static in the normal way. As noted in the example they are called as normal instance methods: 's.MD5()'. I am not sure about this, but I doubt that it is possible to make *virtual* (polymorphics) extensions (as they are not defined in a class hierarchy).
74. On Mar 08 2006 @ 22:41 guest wrote:
For the person trying to understand what is the point of Object initializers,Which version is easier to understand when you read it?
// The "old"/regular way
Person p = new Person("Niek", "Male", true ); // Create object
When you read this, you have no idea what the 'true' boolean parameter means so its harder to debug/understand the parameters. Plus, since both "Niek" and "Male" Are strings, are they in the correct order? If you switch them around the code would still compile just fine leaving you to figure out the bug this causes elsewhere in your code.
// New way
Person p = new Person { Name = "Niek", Gender = "Male", Active = true };
This is Much Much clearer. No way to screw up the parameter order and its clear the boolean 'true' refers to an Active field. This is one of the many things I like about Objective-C and Smalltalk and its something most langueges should copy IMHO.
-Pablo
75. On Mar 08 2006 @ 22:50 guest wrote:
Thanks for skirting the issue #72...real productive...76. On Mar 08 2006 @ 23:03 guest wrote:
btw...almost every linq/var-usage example i saw on the MS website does exactly what you say is bad programming practice...77. On Mar 08 2006 @ 23:05 guest wrote:
I have a question about var: Will intelisense pick up on the members that the inferred class contains to code against in later lines of code?Maybe it doesn't matter. In the case of anonymous classes, there won't be much to think about. Hopefully, you just created the class, know what it contains, and won't try and use that class too far beyond the scope of its creation.
I think that what everyone should be complaining about or figuring out how to avoid is abuse of var. If intelisense does not pick up on the members in the inferred class, coding against it will be difficult to say the least. Maybe that's some built in protection against abuse though; programmers won't use it unless necessary.
On a slightly different note, someone above pointed out how var helped hide all the extraneous info around data and let you focus on the data. There's a framework I believe MS has been talking about that contains, as one example, an employee object. This object can be extended and changed so that all of your applications from say active directory to CRM to e-commerce can pass around one employee object and cast it to whatever type is needed. But what if all I care about is the username and password and I really don't care which type I have, var sounds like it could be convenient there. Does var fit into today's coding standards, probably not. But I also don't believe the full potential of var and the other language features that make use of it were even hinted at in this article.
On the subject of strong vs weak, static vs dynamic typing, can't reccomend the following post enough. The reply from Vassili Bykov is particularly good. http://www.cincomsmalltalk.com/userblogs/buck/blogView?showComments=true&entry=3252458583
78. On Mar 08 2006 @ 23:07 guest wrote:
You guys are all set off because they used "var". It's not like the VB var.A similar proposal has been made for C++, called "auto".
It's easier to see the win in C++. Let's say I have a list of strings,
list<string> foo. (We'll ignore the std:: for now). To iterate through
the list of strings, I might have to write something like
for (list<string>::iterator p = foo.begin(); p != foo.end(); ++p) {
do_something_with(*p);
}
If the proposal is accepted, we can just write
for (auto p = foo.begin(); p != foo.end(); ++p) {
...
}
The language is as strongly typed as it ever was. auto, or var, says to pick up
the type from the type of the initializer.
79. On Mar 08 2006 @ 23:09 guest wrote:
wow, and there I was thinking that Java is threatened by .NET. It looks like despite some interesting new language features, the c# world is filled with so many idiots that it won't make a blind bit of difference.Haven't any of you naysayers wondered why the unnecessary duplication in declaring: Object object = new Object(); exists, given that the compiler obviously knows that object is going to be an Object if that's the type that's going to be assigned to it.
Note:
* It's still strongly typed: IT'S NOT A VARIANT (for those of you hard at reading)
* It won't make debugging more difficult because it's still strongly typed so it'll look exactly the same in your debugger
* var x = new Object(); is pretty easy to read (except for those of you hard at reading)
80. On Mar 08 2006 @ 23:09 guest wrote:
To respond to comment #60.Do extension method work only for static (class) methods? Or for regular method declarations as well... For instance look at this snippet from the wiki you reference:
"Methods within categories become indistinguishable from the methods in a class when the program is run. A category has full access to all of the instance variables within the class, including private variables."
Now if C# will allow me to add a collection of methods to a class and have those methods "belong" to instances of that class... Well that would be phenominally cool.
81. On Mar 08 2006 @ 23:17 guest wrote:
All Python inspired.82. On Mar 08 2006 @ 23:18 blinks wrote:
On the var keyword: it's type inference, a great thing. See the wikipedia article: http://en.wikipedia.org/wiki/Type_inference83. On Mar 08 2006 @ 23:22 blinks wrote:
And #81 - Python doesn't have type inference. Great language, yes, but just because all you have is a hammer, not everything is a nail.84. On Mar 08 2006 @ 23:39 guest wrote:
For all the badmouthing I hear about Java, at least they think good and hard about features and keywords in the language. I wish the C# language designers had taken a step back even before this. If you want some dynamically typed language that MS can control, develop C# Script or something. I'm serious.85. On Mar 08 2006 @ 23:39 guest wrote:
#3"That's nothing. I used VB 3.0."
I had been programming for 10 years before VB 1.0 came out.
I developed on PDP11s, CDC mainframes, dBase II on the original IBM PC, and 6502 on my Apple II.
86. On Mar 08 2006 @ 23:51 guest wrote:
These are backward steps - none of them add anything beyond minor convenience and any time spent on them could have been spent more productively87. On Mar 08 2006 @ 23:53 guest wrote:
34, 59, and 73 are correct explanations, in case anyone didn't want to read this whole discussion and skipped to the bottom.Variables can't be initialized without a type. Anonymous types don't have an accessible name associated with their type. "var" will be filled in by the compiler with the correct type. Static typing is not lost. It's unfortunate that the original post says that "var" is there to save typing, as that's really not its primary purpose.
88. On Mar 09 2006 @ 00:08 guest wrote:
looks just like javascript!!89. On Mar 09 2006 @ 00:54 zing wrote:
> If the proposal is accepted, we can just write>
> for (auto p = foo.begin(); p != foo.end(); ++p) {
> ...
> }
>
> The language is as strongly typed as it ever was. auto, or var, says to
> pick up the type from the type of the initializer.
And what type would that be? I shouldn't have to waste time reading through the API documentation to find out.
Seriously, lazy coders can be helped in ways that don't impact the people who have to review the code. For instance, an IDE might auto-insert the type for a for loop when doing an iteration. Hey, wait a minute... IntelliJ IDEA already does that for me in Java, so my conclusion is that this stunt is just because Microsoft don't want to add actual convenience to their own IDE.
For anonymous classes, that's fine. But I think they should have just come up with a more sensible name. "anonymous", for instance, would have been a perfect name.
90. On Mar 09 2006 @ 01:29 JimBolla wrote:
The "var" argument is ridiculous. Of course we can all come up with horrible examples of how var would make the resulting code unreadable. *Don't use it in these scenarios.* Conversely, one could take ANY language feature and show an example where it makes the code worse. As a language feature, it is a catalyst. It will make crappier programmers even crappier, and good programmers even better. STFU RTFM N00b LOL OMG ROOFLES. Let's all get back to work.91. On Mar 09 2006 @ 02:39 guest wrote:
I see a huge problem with:var o = new { Name = "Niek", Gender = "Male", Active = true };
You can't return nor pass that object 'o' to any other function. Basically you are just making a shorthand notation for 3 local variables (Name, Gender, Active).
That severely reduces its practicality.
92. On Mar 09 2006 @ 03:36 guest wrote:
Guest# 21 said:"Boo (http://boo.codehaus.org) has most of these features already!
Statically Typed, Extension Methods, Type Inference, lambda functions, etc
But also has built-in support for Arrays,Lists,Regular Expressions,Templating, etc. Oh well maybe the rest will come in C#4"
Which is pure horseshit. c# has Arrays (C#1), Lists (C#1&2), RegEx (C#1), Templating(C#2).
93. On Mar 09 2006 @ 03:56 guest wrote:
I added file handling to a Basic interpreter in 1968. I held the actual notebook in my hands in 1962 that was usd to design the first version of FORTRAN, and I also programmed a computer with vacuum tube memory in 1962. I had to wait a long time for VB1!To me the "var" concept simplifies the creation of computer-generated code. I doubt readability is a real issue.
- tobias d. robison
94. On Mar 09 2006 @ 04:18 guest wrote:
Just make yourself happy and use Python or Ruby. :)95. On Mar 09 2006 @ 04:23 guest wrote:
Seems to me the point of using LINQ isn't for dog-simple examples like selecting all the integers less than 5 from a list - SQL's strength is that you tell it *what* you want, and it figures out *how* to do it. This is particularly helpful when you're doing relationships between three or more sets, filtering out certain tuples/objects/rows, aggregating information, filtering the aggregates, producing results in a specific order, etc. Its basically a more natural language for specifying set operations."Embedded SQL" is, of course, one of the oldest ways to interface SQL libraries with C code, so its amuzing in a way to see it come back into vogue, but its great to have it in a strictly-typed language instead of old-skool macros. I hope more languages add this kind of feature.
The real beauty of embedding SQL syntax into the procedural language grammar is that it has the potential (if done right) to eliminate an epidemic class of application vulnerabilities, those of the SQL injection variety.
When application engineers have to treat SQL as an external command language, they think of SQL statements as strings, and do silly things like concatenate external variables into their queries. By moving SQL select semantics into the parent language, the parent language can guarantee that external input cannot change the semantic structure of the SQL statement.
Some might argue that this needlessly complicates the language, but I think that's taking a too-small view. The language (c# in this case) is a tool to help you solve problems. Having to generate correct SQL statements as strings, manage the execution of the statements, retrieval of results, etc. makes the job of correctly solving the problem harder! That's because keeping c# "simpler" by leaving SQL out of it doesn't make the programmer's job any easier - they still have to know SQL, only now its a real bear to use because its an external thing with libraries, objects, and query strings.
Moving SQL into the parent language makes the programmers job easier because they don't have to worry about correct escaping, connection strings, non-native error handling, type safety, cursors with scrolling, bookmarks, etc.
pbrass
96. On Mar 09 2006 @ 04:48 guest wrote:
Wow! Most of you people are absolute idiots. These features will be very helpful in to some people, and maybe absolutely useless to other people. Bottom line -IF YOU DON'T WANT TO USE A PARTICULAR FEATURE (OF _ANY_ LANGUAGE), THEN DON'T USE IT!!!
The choice is yours! Same as you have the choice to use C# or not.
97. On Mar 09 2006 @ 05:33 HarshChaudhary wrote:
All I can say is: HAAH HAA! Think of the simpson bully's voice here. There's nothing innovative here. Only new crap! I think C# is now trying to be Ruby(or insert your favourite functional language here). MS really needs to make up its mind about whether C# should be a clone of Java or Ruby.As far as LINQ being innovative goes, its supposed to come out next year. In the meantime, check this out:
http://sourceforge.net/projects/saffron/
The Saffron project is an extension to Java to incorporate SQL-like relational expressions.Java already has it working. Personally I think its another hack for the PHP/scripting crowd. I am perfectly happy with calling procedures from JDBC.
Harsh Chaudhary.
98. On Mar 09 2006 @ 05:53 guest wrote:
in real world "more language constucts" mean "more problems ,more time and RAM to interpret ..." So right question is not what the language will do for me , but how to do less ... From that point of view it is unlikely someone to invent better language than LISP , or better object-oriented language than Smalltalk , or better interoperability protocol than Java ... and if You want to see what a variable is and how many characters are needed to say "it is variable" try Mathematica (- the answer of the last question is - only one -'_')If You really can't forget the bad joke named Pascal ...look for psychoanalyst not for another language and place to use "var" and remember Gresham's Law
99. On Mar 09 2006 @ 07:22 guest wrote:
var is typed! It's just a shorthand. Eg. MyObject obj = new MyObject();. This can be written as var obj = new MyObject(); and an obj is always of type MyObject.100. On Mar 09 2006 @ 08:13 Melwyn wrote:
LINQ concept is possible when files in the system is stored like Relational database management system. And thats why microsoft is betting big on ORDBMS.101. On Mar 09 2006 @ 09:57 aptx49 wrote:
var =ambigousI think it is not nice feature
i dont really know what C# 3.0 want to be ...
i Think java i s good one .
102. On Mar 09 2006 @ 10:00 guest wrote:
"var" typing: bad, unreadable code. Confusion without saving ANY time at all."initializers": bad, confusion code. Which constructor is being called? Why not write a constructor if something _needs_ to be initialized at creation time? Does not save typing, just saves lines. Stupid.
"Anonymous types": might be useful.
"Extension methods": very confusion, and besides I do not get the syntax _at all_. I'd say this is potentially _very harmful_!
LINQ: dont get to the embedded SQL prawn, will you???
103. On Mar 09 2006 @ 10:12 Christiaan wrote:
Why is there a "var" added?? Simple, otherwise anonymous types wouldn't be possible.I think anonymous types are real time-savers and keep your project clean (no single use classes etc.)
Everybody is way to hard on the "var" supplement, I think it could be realy usefull and with anonymous types it's the only way. Just remember, this is an add-on not a replacement! If you want to strongly define what type a variable is just go ahead!
I think all new features are really nice features, especially LINQ DLINQ and XLINQ
Common, try it and I think you will all fall in love with C# 3.0, at least I did
104. On Mar 09 2006 @ 10:30 l0ne wrote:
@ #102: Try typing HashTable<String, ArrayList<int>> collection = new HashTable<String, ArrayList<int>>(); and you'll appreciate var. It's not mandatory, and if you want to explicitely state the type of something for readability you're free to do it.Also on extension methods: Objective-C has had them for decades (categories) and they're extremely good, as they allow you to seamlessly extend objects that you don't have the source to -- ensuring you don't have to code public static members of _your_ classes when all you want is to eg transform or enhance an object of _another_ class, making code much more readable and concise. (Should ToMD5() reside in the String class and called as str.ToMD5(), or should it instead be something you write as MyStringUtilities.ToMD5(str)?)
105. On Mar 09 2006 @ 10:36 Guest wrote:
You seem to have missed the point, completely.The "var" type adds a lot of value, and is not meant for silly things such as an "int" replacement. See this example;
JuniorSalesEmployee e = new JuniorSalesEmployee();
var e = new JuniorSalesEmployee();
18 keystrokes saved!. If the object type is obvious WHY REPEAT YOURSELF? Maybe so you can justify to your boss the long hours a Hello World takes in C# as opposed to Ruby/PHP/bla/bla?
106. On Mar 09 2006 @ 10:37 guest wrote:
Exactly right, No. 95.<Visual Foxpro>
use mydatabase!mytable
begin transaction
update mytable set field1 = "binky" for field2 = .T.
end transaction
</Visual Foxpro>
So how much would you have to do in C# 2.0 to get a transactional update like that? Hopefully LINQ will approach that sort of brevity in C# 3.0. Admittedly the above is for native DBF files but presumably the equivalent for LINQ would be MSSQL.
107. On Mar 09 2006 @ 11:02 guest wrote:
var my_proc_1 (var a, var b){
return my_proc_2 (a + b);
}
var my_proc_2 (var c)
{
if (my_proc_1(c, 1) < 10)
return my_proc_2(c, *c);
else
return c.ToString();
}
class some_complex_object
{
operator + () ... ?
}
void main ()
{
var d = my_proc_2 ();
// imagine that you work for a real company with millions of code
// written by real programmers which know next to nothing other
// real programmers have written and try to fix their bugs
}
"var" is strongly typed but it belongs in dynamically compiled languages. Perhaps what's confusing everyone is that C# is a strongly typed language, yet it still is a dynamically compiled language, sort of like XQuery. The abusive use of these syntax is one subject conservative C++ standards guru try to avoid in the language. KISS. Though you can save keystrokes, you add hours in debugging time. Oh wait, you don't have a real job do you?
108. On Mar 09 2006 @ 12:17 guest wrote:
#107, from what I can tell that scenario isn't possible, since the compiler won't be able to infer the type of the var in the return values and parameters.CODE: CSHARP
// valid
var foo1 = 1;
// invalid
var foo2()
{
return 1;
}
var foo1 = 1;
// invalid
var foo2()
{
return 1;
}
109. On Mar 09 2006 @ 13:17 guest wrote:
Var is probably going to be typesafe, but not moronsafe. In use with anynoumous types it's neat, but what's scary is examples like var abc = 25; This encourages the novice programmer to really not give a shit about what's really happening, and it's bound to create debugging headaches. For saving keystrokes, the '?' in #Develop which poster #47 talked about is a much better way to do so. This will also render the code readable on print.The object-initializers is superflous, C# has constructors. And the extension methods are horrible. The primitives sould be left alone. Encapsulation gives you all you want, and leaves the primitives intact.
And to all you guys screaming about not having to use the new features. Well this approach works as long as youre programming ALONE. When you get in a tean and have to work on, read, debug, etc, code that OTHER PEOPLE have written, and only God knows what they can be up to regarding idiocities. To say "you don't have to use it" about these features is quite comparable to say "You dont have to use narcotics" and legalize them. Someone is going to do so, even if its stupid. And then it's going to affect the rest of society.
110. On Mar 09 2006 @ 13:28 guest wrote:
"IF YOU DON'T WANT TO USE A PARTICULAR FEATURE (OF _ANY_ LANGUAGE), THEN DON'T USE IT!!!"Sounds great in theory, but wait until you have to maintain someone else's code which is littered with bizarre operator overloading and other annoying tricks.
111. On Mar 09 2006 @ 13:33 biologic wrote:
First things first, I think it is early to speculate on C# 3.0 cause we are still warming up to 2.0.As I understood, "var" is used for delaying the type of the variable from the beginning of the statement to the end. I mean if you are writing code in a way that you decide on variable types on the fly, that's an improvement for you, but I don't. Moreover, it is a bit vague (or implicit) on what the compiler will decide to use. int16/32/64
Anonymous types, on the other hand, seem very handy esp. if you use reflection.
As one of the commenters said, these are new features, nobody is forcing the use. Let time decide the use of them.
112. On Mar 09 2006 @ 14:10 guest wrote:
"The problems with Java far outweigh this added initializer convenience. I will never go back to Java no matter how much they pay me. "Write once, run everywhere". Yeah, nice try. Even c# apps run better on Linux than Java. lol"lol
Quick quiz: How many fortune 500 companies are using MONO on a Linux server in production?
< 0.01% (MORE LIKELY NONE)
Question 2: How many fortune 500 companies are using Java on a Linux server in production?
90%+
BTW Did you know that Java are heavily used by both Google and EBay?
We develop on Windows and deploy to Solaris (SPARC and x64) without any portability problems. Java is widely used on every major operating system available today (Windows, AIX, Solaris, HP-UX, OS-X, Linux etc.) If you think .NET is more portable you must be high on something.
Visual Studio only runs on Windows whereas NetBeans (www.netbeans.org), Eclipse (www.eclipse.org), Studio Creator (http://developers.sun.com/prodtech/javatools/jscreator/) and JDeveloper (http://www.oracle.com/technology/products/jdev/index.html) run on every major OS. And best of all they are all free (even for commercial purposes).
Do you seriously think that monoDevelop, sharpDevelop can compete with these tools?
Then there is the minor issue of Java being *MASSIVELY* faster than MONO and faster than MS CLR:
http://www.shudo.net/jit/perf/
Run SciMark for yourself if you don't believe me. The C# and Java sources aren't hard to find. Even the client VM for Java is faster than .NET 2.0 since JDK 6 beta. Server VM has always been faster than .NET. Three years ago's JDK1.4.2 server VM even puts .NET 2.0 to shame in SciMark.
And the fact that there are more jobs for Java than C#:
http://mshiltonj.com/sm/categories/languages_a-m/
And Java has more mindshare:
http://www.tiobe.com/tiobe_index/index.htm
And the fact that Java is supported by every major IT vendor on the face of the earth (Excluding MS of course):
http://www.jcp.org/en/participation/members/
113. On Mar 09 2006 @ 14:21 guest wrote:
I'm not going to trash it because its MS, but it all seems somewhat odd. All of us who have been doing software develop for sometime knew that with the web and the massive amounts of data being compiled that someone was going to try and integrate a feature such as Language Integrated Queries into a programming language to help with the problem of handling so much data. I knew when they started talking about Language Integrated Queries that some odd looking features were going to be added to support it. Welcome to Software development of the future... 06 style... And guys, they whole var thing is for retrieving information from a query, quit trying to use it for something it was not intended for so I don't have to see 50 million articles about why var is evil or bad just like we saw about alot of C++ feature some moons ago because people abused it.114. On Mar 09 2006 @ 14:29 guest wrote:
Ye olde javascript is back again..115. On Mar 09 2006 @ 14:53 guest wrote:
Take all the syntactic and semantic sugar from Ruby and the straigthness of the languagedesign and you will have a REALLY good language without such unneccessary "workarounds" like VAR (when i have to type Var i=5 i also can write directly int i=5, there is NO advantage of VAR).Please, please, get rid of this awfull C and C++ stuff. Take a step forward to REAL OOP and ... and... etc...pp
I´ve learned Pascal, Cobol, C, Assembler, PHP ... and took a look at Java, C++, Ruby and some not so common languages. I found C++ only usefull for systemprogramms where speed is the most nessessary thing, Java is a castrated C++ with workarounds to make things from C++ "work" and much to overloaded and NOT realy OOP i.e. because of the differenz between int, double,... (no objects) and "real" objects. In german I call it "sperrig", I am feeling uncomfortable with java. When I get in touch with Ruby I saw that there is indeed a possibility to have "real" OOP (i.e. everything is an object) and much other comfortable and easy minded things. Ruby on Rails is not the end of the advantage of it. I think that there will come more of such advancing things.
So, reading of those "new", "cool" things of C#3.0 makes me loughing and angry. It is like fooling the programmers. Cause these "features" are NOT NEW (just for C#3) and pretending that they are is NOT NICE. The same with AJAX, a real OLD thing, that could also be done with a small javaapplet in a nodimensional frame. The hype about AJAX (and C#) is funny. Believing in such things means making M$ ruling the world.
116. On Mar 09 2006 @ 15:02 arthurmnev wrote:
1) How is 'var' is different from 'object'? aside from that - i would really hate to see abstracted data types. This is exactly where entry level developers will cause chaotic performance issues.2) What I would like to see though is an ability to deal with char[] as a string, perhaps allowing to declare a string data type that behaves more as an array of characters rather then .NET string (immutable constnatly copied region of memory). With full understanding that .NET utilizes string data for quite a few internal operations - a new data type seems to be in order.
3) GDI library bridge - there is rather poor support for GDI as of version 2.0 and some for GDI+; GDI+ is not always suitable (i.e. string based operations instead of character based stuff).
There is more, but this should be a good start.
117. On Mar 09 2006 @ 15:30 guest wrote:
Everyone should take a look at Anders Hejlsberg's demo on LINQ before expressing your thoughts about these changes. All these changes are for this one particular purpose: LINQ. And it's great.http://channel9.msdn.com/Showpost.aspx?postid=114680
118. On Mar 09 2006 @ 16:18 guest wrote:
These are great changes, keep up the good work! If you want to use Java use Java, or use C# in it's traditional manner, but don't slow the rest of th world down.119. On Mar 09 2006 @ 17:10 l0ne wrote:
@ 116: this is the part nobody actually bothered to understand.var is not a type!! var is replaced at _compile time_, not at runtime by whatever the type of the initialization expression is.
var x = 120; will make x an int. var myCollection = new ArrayList<HashTable<string, ArrayList<int>>>(); makes x an ArrayList<whatever>, so that you don't have to type it twice. This is strong typing: trying to do x = "Hi!"; to the last x variable (the ArrayList) will generate an error.
"var" is essential for anonymous types above, as they don't have a name or an interface or superclass (other than Object, of course) that you can use to label the variable.
120. On Mar 09 2006 @ 17:51 guest wrote:
Oh my god ... I can see ...Another good ways to produce more and more unreadable code, and bad quality softwares.
Please, please: do not use 'var', please ...
121. On Mar 09 2006 @ 18:18 guest wrote:
> IF YOU DON'T WANT TO USE A PARTICULAR FEATURE (OF _ANY_ LANGUAGE), THEN DON'T USE IT!!!ok...so you and I will work on a project together and i will change our code to look like this:
CODE: CSHARP
just because the language allows it and I like it better :P
122. On Mar 09 2006 @ 18:35 Guest wrote:
Everything cool except "var".This "var" make code messy and harder to read. I prefer selfcommenting code (with meaningful variable and class names). And it doeas not save any keystrokes beacuse when you type for example:
JuniorSalesEmployee e = new
Than VS (intelisense) will write for you constructor name: JuniorSalesEmployee()
And if you have more than one constructor than give you possibility to select one you want.
123. On Mar 09 2006 @ 18:39 guest wrote:
Ooh ... var! Now that is just plain scary. Hate to think how many shades of brown most people here would crap their pants if the 'new' keyword went away too, as in both Boo and Nemerle, so that a programmer could just express a declaration in this way:person = Person()
Jeepers! And you thought the Exorcist was creepy! What is even more unsettling is that this line is 100% strongly typed, and it didn't even need a var. Talk about facing the insanity of seeing the almighty Cthulhu! Where is a good nursemaid when you need one?
Open your minds a bit people. And for gosh sakes, quit threatening to go to Java and just make the trip. I have to work with that language day in and day out, and I would jump at the chance to work with C#, Boo, Nemerle, etc. I think there are a lot of folks here that have rather less experience with the 'joys' of Java (you know, like the 'joy' of growing bamboo shoots under ones nails) than they would like to let on.
The real problem with the word 'var' is that it is different, and people always fear the unknown. It scares the bejeezus out of folks when something changes, even when it could help them. This is why, inexplicably, programmers in my experience rarely become fluent in more than one or two languages.
And to #92, do some research before you open your mouth. The original post claimed that Boo had built in support for those things, which is different from library support. It is the difference between the support of lists in Nemerle and the support of lists in C#, VB.net, etc, which is somewhat vast if you care to do any amount of research at all.
Cheers,
Steve
--
124. On Mar 09 2006 @ 18:48 guest wrote:
Oh, and another thing...For all the folks carping about Intellisense, realize that 5-10 years ago yours peers would have snorted derisively and made some comment starting with the words 'Real programmers don't ...'. If your theory of how great code is written would break down without an IDE to use, I would submit that your grasp of the subject isn't very sound in the first place.
Cheers,
Steve
--
125. On Mar 09 2006 @ 20:29 guest wrote:
I get what var is. I still dont like it. It will make reading code harder (as if thats not already hard). And even though the C# impl of var isnt completely like the VB days, it will still cause problems like it did in VB. Lazy/ignorant programmers wont be thinking about data types....and that is important, even today.And really, does typing var save that much keystrokes...common on Im not that dumb:
var vs int no chg
var vs string +3 for var, big deal
var vs double ditto
var vs float +2 for var, again who cares
if one is that lazy that var is better that float they shouldnt be programming....
126. On Mar 10 2006 @ 05:34 guest wrote:
Give C a chance. When's the last time you saw a popular application for Windows written in any scripting language?127. On Mar 10 2006 @ 05:48 guest wrote:
Use the C language, real C++, or any kind of COMPILED language. Think of the everyday software: Adobe Photoshop, Microsoft Visual Studio, Mozilla, Internet Explorer, SmartFTP, Opera, AOL Instant Messenger, mIRC, ... All robust, quick loading, C applications. Oh yea, did I mention every SINGLE game programmed within the last 10 years is probably written in C/C++/ASM as well. How many NEW programmers are starting with C? Absolutely none. Why?!128. On Mar 10 2006 @ 14:31 guest wrote:
I've been through the gamete of languages in my short time as a coder, from C to ActionScript to Lisp, and there will never be a more powerful language than C. Even if a newbie starts off learning C# they will never be a powerful coder like that of a C coder. C coders depend on nothing. From bitwise operations, the lovely malloc and its good friend free we (C coders) write it all from scratch.The guest who said they'd move over to java (blah!) permanently if C# 3 began to resemble VB was not funny at all. You need to go in a room and think about what you just said.
129. On Mar 10 2006 @ 14:49 guest wrote:
Sweet!var isn't that amazing. Autocomplete takes care of most of my type-name keystrokes. My guess is that smart programmers will try to minimize its usage for readability reasons. Also, if visual studio is going to have to evaluate it in real time for autocomplete to work, it might as well replace the 'var' with the real type-name as you type.
However, being able to initialize structs at declaration would be fantastic (They can't have constructors in C#, and sometimes you don't want the overhead of a class, want them to not be nullable, or need to pass them to external (C++) methods.)
The extension methods are perhaps the thing I'm most excited about. Now I can finally add methods to sealed classes. To you naysayers, I'm not certain, but I'd imagine you can only access the public methods of the class you're extending (in the case of the example, .ToString()). Encapulation is maintained (preserving the intent of the sealed class declaration) while still allowing the end user to effectively write the derived class they couldn't make.
And as a side note, I would bet that few people who love java have had to write a memory efficient, speedy application with it. All the large java applications I've seen have been slow memory hogs (eclipse, net beans, azeureus, etc). I'd never use java on a server... ever. IBM and SUN promote it because they'll also sell you the extra hardware you'll need to scale out.
130. On Mar 10 2006 @ 18:47 guest wrote:
That's nothing... I'm still using VB 3.0 at times. As well as 6. And .NET.131. On Mar 10 2006 @ 23:41 Gumoz wrote:
var is for C# what id is for Objective-C.why C# People have not designed those features from the beginning?.
ObjectiveC rocks!.
132. On Mar 11 2006 @ 06:48 guest wrote:
hey...this is starting to look like Ruby...especially the Object Initializer example...133. On Mar 11 2006 @ 15:52 guest wrote:
Actually, it's starting to look like boo: http://boo.codehaus.org/134. On Mar 15 2006 @ 07:14 l0ne wrote:
@131: No it is not. "id" is to Objective-C as System.Object is to C#.You cannot change the type of a var-declared variable in C# after you declare it -- it's simply shorthand for when the type gets so long that typing it twice (once in the declaration, once in the constructor) would be overkill.
135. On Mar 15 2006 @ 18:24 mashi wrote:
Please don't pollute my favorite language..http://www.mashiharu.com
136. On Apr 09 2006 @ 22:14 quest wrote:
this think with people that not regognize the difference from variant of vb with var of c# it sucks. Im Vb developer and the last 2 months i use c#.Variant is a type in vb, var keyword in c# itsnt type variant is a special keyword for auto selection of a type from language.
var s = "this is a string but var keyword isnt type but a keyword"
ohh yes if you dont understand yet = now s is string type NOT VARIANT TYPE.
137. On Apr 17 2006 @ 23:49 guest wrote:
I guess there are basicaly two different problems:1. People don't like var keyword. Period. Simply don't like. This makes C# too VB-like, or too JScript like.
2. People like auto keyword. This makes language look more like a modern C++.
Solution: instead of using 'var' work Microsoft should use 'auto' word.
Now it clealy states that type will be automaticaly deducted and that its not a variant. And C# again closer to C++ syntax then to VB.
138. On May 05 2006 @ 13:38 guest wrote:
oooh, so much fuzz for stuff I already know from lisp. microsoft just rips off lisp ideas... fscking bastards, they never invented anything139. On Jun 04 2006 @ 08:11 JosephDeCarlo wrote:
I see the reason for the var keyword with regards to integration with LINQ and the necessity of the keyword for anonymous types. I don't exactly see the uses for anonymous types, but I didn't see the uses for anonymous delegates until I really started using C#2 (they share a lot of the power of functors in C++).I think it is very important for the user to know what class he is getting. Let's hope Microsoft makes the declaration type and IntelliSense of the var'd variable usage work with the type intended to be assigned and not necessarily the type in memory.
The examples given use very simple expressions like var x = "my value"; which is obviously a string and x's type and IntelliSense should be that of the String class, but what happens in this scenario?
CODE: CSHARP
public IAbstraction GetAbstracted()
{
return new ConcreteAbstractionWithExtraMethods();
}
var s = GetAbstracted();
{
return new ConcreteAbstractionWithExtraMethods();
}
var s = GetAbstracted();
Well if Microsoft does it right, the compiler will declare s as IAbstraction, but if they make var s of type ConcreteAbstractionWithExtraMethods since that is what is actually in memory, then the abstraction layer is lost. Furthermore, it will compile and the consumer may use methods of the ConcreteAbstractionWithExtraMethods that are not in the interface without even being aware. This could be a major flaw in the language if done without care.
140. On Jun 21 2006 @ 15:50 guest wrote:
public IAbstraction GetAbstracted(){
return new ConcreteAbstractionWithExtraMethods();
}
var s = GetAbstracted();
141. On Aug 18 2006 @ 21:59 guest wrote:
Wow guys, if you don't like the new features, you can stick to 2.0 syntax, it will still compile and run. I personally like the idea of being able to filter objects with LINQ, so I'll occasionally use the var keyword I'm sure.I'm not going to reiaterate the obvious things that the whiners are missing about strong typing and static-ness, but one thing I'd like to point out to those of you munching about Java: Java is an interpreted language which CAN be JIT compiled, but when run on a virtual machine ISNT, whereas c# and any .NET are NOT EVER run on a virtual machine. They do have an IL, but it's actually still JIT compiled to real native code every time before a bit of code is executed. (You still need the assembly around for the meta data, because that doesn't go into the native image) In many architectures, it's just a matter of which syntax you like better (Java or C#), because they do the same things JIT compiling, but in some cases, Java is only interpreted which is up to 25 times slower than the JIT compiled version of the thing. So, there's the truth. If you like true platform independence, stick to Mono :)
142. On Jul 28 2007 @ 00:22 growUpPeople wrote:
It seems to me that some people need to do a little more research (other than reading this article, which is nice, by the way) before bashing new features. As many (more informed) users have said, no one is forcing you to use these features. In fact, if you love <insert your language name here> so much, use it! If you want it to run on the .NET platform, you can even write your own implementation of the language using the features in the .NET framework, and the C# compiler (at least until you have your own compiler for your language). I'm sure that if you do, you will come to appreciate many of the new features in C#. I find it supremely annoying for people to complain about features in a language that they don't even know well, or use for serious development.As for the var addition, it is useful. If you don't like it, then you can manage several different data structures (since you love typing so much!), and change them all when your usage requirements change (a thousand times during development). Or, you can simply change the var declaration, and let the compiler recreate your simple data structures for you.
Before you criticize new technology, learn something about it. Oh, and another tip, use a spell checker. You seem like an idiot when you can't spell! Spell checking is integrated into so many tools, there is no excuse, other than being lazy (I suppose you could dislike the spell-checking feature as well, thinking "I can spell check my own stuff!", which would fit in with all your moaning about new features to a language you don't even use) or stupid.
Mono will implement these features as well, so you won't get away from it by switching to mcs (if you use Mono, you know what this is).
To the people who love typing, why don't you just program everything in cil? As for me, if I can save time and get more done, I'm happy, and so is my employer.
1. On Mar 08 2006 @ 20:14 guest wrote:
"var" keyword.... no no no no NO NO NO!I'm old enough to remember VB6 ;-)