Home > .NET > New Language Features in C# 2.0, Part 1 New Language Features in C# 2.0, Part 1 Eugenia Loli 2004-04-07 .NET 33 Comments Four years ago, a new upstart language named C# surprised the development world with its elegance and consistency. In this two-part series, you’ll get a first look at three of the four major language refinements in the latest version of C#. About The Author Eugenia Loli Ex-programmer, ex-editor in chief at OSNews.com, now a visual artist/filmmaker. Follow me on Twitter @EugeniaLoli 33 Comments 2004-04-07 12:28 pm It’s nice to see that VS.Net 2005 will support the split of the actual workings of the code, and the form behind which it resides. This reminds me of VB6 (eeeks, painful memories) where you were unaware of how the form design was being handled, you just had access to the code behind it. Its good to see you have the option to show the designer code as its often necessary to edit that by hand rather than using the designer. I think this split is a beginning to encouraging developers to split core/interface code in preparation for XAML and all it will offer. 2004-04-07 1:15 pm …so this “elegant” and “consistent” language is guaranteed to thrive. 😛 2004-04-07 2:14 pm R – Obvously you havnt used C#, it does have some very Java like looks and feels but there are some things you just can’t do with java, plus java is very very slow compared to C# when it comes to GUI apps. I use both, they both have their purposes. 2004-04-07 2:34 pm Unlike Java, C# 2.0 seems to be getting with the 20th century and embracing features like lambdas (anonymous functions). Generics in C# 2.0 are also looking much nicer than the hacked-up generics in Java 1.5. I rarely have reason to applaud Microsoft, but their C# group deserves praise for trying to go beyond the status quo. 2004-04-07 2:36 pm AFAIK Python has anonymous function, yield return, etc. And it works dramatically easy and interesting 2004-04-07 2:46 pm Python, however, is not targetted currently at regular application development, and is not popular in that area. The key thing here is not that you’ve got a language that does the things C# 2.0 does (we’ve had those for decades) but that we’ve got a language pushed by a major corporation that is starting to incorporate advanced features. 2004-04-07 2:46 pm NET’s favorite language is back with some new innovations 1. anonymous (lambda) function -> Lisp has it since ages, Java has it for the same purpose… 2. Iterators -> I’m impressed…Not! (Ruby, Python) 3. Partial Classes -> Looks like a hack for bad programmers Except for 3. I only see must-have features but nothing new. 2004-04-07 2:46 pm …like COBOL is elegant 😉 2004-04-07 3:02 pm I almost spit out my Diet Coke. =) I think some may claim good consistency with C# (e.g. boxing, API) but it’s far too similar symantically to Java to shine on its own. The power of C# only comes to light when used in conjunction with .NET and ASP.NET, I think, and that’s a complement to those platforms/frameworks which have better “elegance.” I think both C# and Java will add small enhancements to their languages, but I don’t see anything revolutionary down the pipe. Any enhancements would probably occur in the runtime environments (.NET or J2EE). Personally, I would like to see a Java rewrite/clean up of the Java API. 2004-04-07 3:11 pm I agree. Although at times it can be elegant, C# can also be as ugly as C++ or worse. Consistency doesn’t exist in it, yet. Example: SortedLists have GetKey(index), but not GetValue(index), you use GetByIndex(index). That is an inconsistency in the language. There is also no GetIndex(key) or GetIndex(value). With ArrayLists you access by index using arraylist[index], but there is no GetValue or GetIndex. At the same time Sorted List uses SortedList[object] instead of index. Little things like this are pretty annoying. There are thousands of these throughout C#. I wouldn’t call it consistent. Maybe a few versions from now these will be fixed. Java, on the other hand, is much more consistent in its conventions. Some of that is better, more rigid design, and some of that is due to its maturity. Java is also elegant in comparison to C# due to a more rigid coding structure. 2004-04-07 3:19 pm http://www.geocities.com/tablizer/miscoop.htm#reinvent 2004-04-07 3:25 pm http://www.ai.mit.edu/~jrb/goo/wiki/index.php?GooWhy OOP can be damn spiffy, it just has to be good OOP. The problem with C# and Java is that they are *all* OOP, rather than making OOP orthogonal to procedural and functional paradigms. 2004-04-07 3:33 pm I am quite sure I have read something about an open source implementation of ECMA C#, CLI and corlib running on multiple platforms including Linux, MacOS, S390, Solaris. Am I wrong ? 2004-04-07 3:57 pm That seems to run parallel to my point. I see C#’s syntax as a mess right now. You can see that different programming teams programmed different parts and MS wasn’t strict enough on conventions. I feel that access should be kept simple and straight forward for everything, but at the same time it needs to remain consistent from object to object. In my example from before, I feel that the lists should both have GetValue and GetIndex and GetKey if the list needs a key. They can be overloaded as needed, but the idea is consistency between the conventions. Accessing one like an array and one like an object even though they are both objects is inconsistent. 2004-04-07 4:50 pm Well there are some Open-Source Implementations: – http://www.go-mono.org/ – http://www.gnu.org/projects/dotgnu/ 2004-04-07 4:58 pm I agree that APIs should be as consistent as possible, but an inconsistency in System.Collections has *nothing* to do with the syntax of the C# language. It is just a library. And I think that the C# collections are quite well designed. Of course they have some minor inconsistencies, but I have *never* seen a class library that is 100% consistent. Accessing ArrayList and Hashtable values using the index operator is much more convenient than using GetValue. 2004-04-07 5:44 pm I like the idea of generic functions (which is what I think Arc/Lisp uses), to some extent. They probably encourage consistency because of idioms, and the fact that functions/methods/messages/whatever are not ‘hidden’ inside classes. 2004-04-07 6:10 pm Java finally got a proper printf(variable length args) after how many years of people wanting it? Java still doesn’t have user defined types on the stack. No matter how much the apologists try to spin it, moving a stack pointer is still a lot more efficient than allocating something off the heap. No operator overloading. BigInteger anyone? No properties, which sucks from a component oriented programming perspective. Thanks for forcing me to organize my packages into a physical hierarchy. NOT! Deployment and the whole CLASSPATH business is still a mess. Java’s generics implementation is a complete hack that will not result in any performance gains and forget about reconstructing types using reflection because it’s still all objects as far as the runtime is concerned. Oh, but I forgot generics didn’t matter to the fanboys until Sun decided to implement it. Delegates are way more elegant than interface/adapter classes for event wiring. JNI sucks compared to Pinvoke. No wonder though, since Sun doesn’t want you hooking up with native code. If I want to drop down into unsafe mode and use pointers I’ll choose that. Thanks Sun, but I don’t need you telling me it’s bad for me. Thanks for making us suffer with Swing for all of these years. Do they still think that non-native look-n-feel is a good thing? MSIL is a much better bytecode to target for multiple languages than java bytecode. I guess you java fanboys should be grateful that .NET is giving Sun a little competition. 2004-04-07 6:32 pm Why are you trolling about Java in a C# thread? Absolutely everything you said is irrelevant to any of the other posts, and irrelevant to the article. Leave your haterade at the door when you stop by next time. 2004-04-07 6:36 pm The main reason is that the C# libraries and tools are mainly proprietaries and aren’t avaiable on Linux. Thanks though, I am looking forward to the day that MS supports Linux. 2004-04-07 6:51 pm I was thinking, to me, programming is essentially the same, you write functions, sometimes objects to model complex or not so complex behavior. You have all these design patterns to help you create bigger systems and tons of libraries that essentially do the same thing, just written by different parties. Take strings for example, MFC uses CString, Java uses String, cocoa uses NSString. They both have essentially the same functionality–searching, length retrieval, replacement, etc. Why are people still re-inventing the wheel? To me, java has some really nice features, C# is a tad more modern, but the elements are still very much the same. If you understand how garbage collection works and the lifetime of objects and how to write functions, etc using somebody’s probably c-like syntax, aren’t you well off? Then the next phase comes to getting comfortable with the environments which your language run under, NetBeans, Visual Studeio .NET, vi, pico, text editor, whatever, gnudebug, shark, etc. here’s my proposal then, a standards body to create code, which essentially does a group of tasks and then have that code translated into whoever’s environment. The syntax will be modelled on c or English, or whatever the majority developers agree upon/find easy. And why not use the MVC pattern while you’re at it, develop some meta-language like html to create gui’s quickly. Then we wouldn’t have all these languages ‘wars’ and everybody would just concentrate on learnign the universal language, much like how Americans and Brits view English, the universal language. C# seems to have really nice features, I haven’t developed for it at all, but I like the features people have listed here. Too bad in a few years there will be a new language to overtake that, new environment, new everything. 2004-04-07 7:02 pm Did you even read my post? Of course I wouldn’t even had to say anything about java if the trollboys hadn’t started in on how c# is just a rip off of java. Nice mod down by the way. I guess I’ll do the same to you. 2004-04-07 7:09 pm There’s not one programming language that fits all needs and a standards body is not going to accomplish anything except for ratifying something that is already designed and implemented. 2004-04-07 7:14 pm It’s kindof ironic that you were saying how elegant java is compared to c# in an earlier post, but then get all flustered when I post how I believe c# and .NET in general is better than java. Wow, you sure can dish it out but you can’t take it. 2004-04-07 7:39 pm Great link. Enjoyed the read. His rant about OO database interfaces reminded me of this article http://www.zend.com/zend/tut/tutorial-wong4.php Another interesting read http://www.tonymarston.net/php-mysql/databaseobjects2.html The article talks about using very little oop in his database access techniques. 2004-04-07 8:02 pm You must not have understood my post. I wasn’t bashing C# or praising Java. I was comparing similar languages. I said that C#’s libraries have inconsistencies in their conventions. I said that this will go away as the language matures. I said that this was what happened with Java. Java got more consistent from 1.0 to 1.1 to 1.2… The same will happen with C#. The only comparison to Java here is the age. I also said C# can or cannot be elegant. It depends on the coder. C# does not have as rigid of coding as Java. So, it is up to the coder to make it elegant. C# is more like C++ in it’s strictness and Java is between C++ and Pascal for strictness. That’s all I was saying. I wasn’t bashing at all. In fact, there were no other threads bashing C# or praising Java. Your thread was the first one, and it was and still is a 100% troll. All you do is bash Java. You don’t mention C# at all and you don’t mention .Net except for once in the second to last sentence. In the last sentence, you blast java developers as fanboys. That is a troll. 2004-04-07 8:10 pm The first article is pretty interesting. The php techniques in the article are different from what I normally do. The second article doesn’t work? At least for me the URL will not load. Is there an alternate URL for it? Thanks for the links. 2004-04-07 9:14 pm Why do people keep saying C#, .NET and its libraries are not supported on Linux ? That’s exactly what Mono does in addition to MacOS X, Linux PPC, … You can use C#, the .NET libraries and many other .NET technologies on Linux. With Mono ! 2004-04-07 9:30 pm I can’t find anything that would justify using partial classes. Maybe someone else has a real good use for it. I would use subclasses. To me, partial classes seems extra “baggage” for the compiler. 2004-04-07 10:06 pm trolls… eww 2004-04-07 10:58 pm I hear the only reason for the partial classes for code generators. 2004-04-08 8:20 am Strange because when I click on the link it opens. If you go to the first link and click on the comment with the title, “close, but no cigar” you will get a link to his article on his website. He comes across as very arrogant, but has some interesting ways of maximizing productivity. Here is the link again. If it does not work try and just copy and paste the in the url bar. http://www.tonymarston.net/php-mysql/databaseobjects2.html 2004-04-08 2:26 pm You write about Lumbhergh (sp?): In fact, there were no other threads bashing C# or praising Java. Your thread was the first one, and it was and still is a 100% troll. All you do is bash Java. You don’t mention C# at all and you don’t mention .Net except for once in the second to last sentence. In the last sentence, you blast java developers as fanboys. That is a troll. Someone is a troll not if he bashes something, but if what he goes on about is a lie/wrong/etc. Now, reading his “Java bashing” post in this thread, what exactly does not hold? By all means, point it out. People should be a little more hesitant to call someone a “troll” or something as “FUD”.