While writing this C# compiler, I've had a chance to get familiar with not just the general C# language, but also the hundreds of little decisions that went into it (little things like overload resolution, attribute subtleties,  or subtle improvements in the switch statement). I'm continually amazed at how these all interlock, enhancing each other, to make such an airtight container. I've also had to work with a lot of Java code once again, while doing this and another project. It was a bit of a surprise, not totally bad for sure, just umm... Maybe like the way old girlfriends can scrunch up their faces while smiling when meeting me again, 15 years later. Anyway, it got me thinking about the whole C# vs Java language debate.

When people compare two technologies, they all two often don't compare the technologies. C# and Java are just one example, OS's are another, SWF and SVG are yet another. Not to digress here, I'll stick with the two languages - but the key word here is 'languages', not lifestyle choices.

C# is a better language. I don't think there is any argument here, in spite of all the arguments about this. While Java may certainly be a better choice, that doesn't make it a better language. Lets go through some of the common arguments one by one.

1) Java is cross platform and C# isn't. I'm not going to dispute it, that is a pretty valid point. Now while certainly there is nothing stopping C# from running elsewhere (after all I'm making it run in swf's), and Mono BSD etc etc, in reality C# is pretty closely tied to Microsoft, and Java isn't tied to any OS. BUT. This has zero to do with a language. This has a LOT to do with what language you will choose for your project, no question. However, this is comparing the Java platform with the .Net platform, C# doesn't enter the picture.

2) Java is more widely deployed than .Net. No doubt. Not sure how that makes debugging easier.

3) Microsoft ripped off Java and now claim it as their own. Hmm, I've always had trouble with that kind of logic. Everything is built on what came before, including Java, including C#, its called progress. Sour grapes do not a valid point maketh. As Java improves, they will be looking closely at C# (unless they are idiots). I know Microsoft PR tilts the other way, saying C# is more like managed C++ than Java (which Java is too) - while there is truth to this, I bet they knew what Java was ; ). Yet, it is not exactly like Java in a lot of ways. And in these ways it is better. 

Oh, and everyone knows that stealing Anders Hejlsberg was way more important than anything they stole from Java ; ).

4) Unsafe code ha ha. Well, here we get into the purpose of the whole environment - Java is meant to be safe always and platform agnostic, C# is meant to be able to (optionally) interact with its environment. While C# can be 'geared down' to be safe, and while Java isn't always 100% platform independent, both are tuned about right to facilitate or prevent interaction with the underlying machine.

5) Java is open, C# isn't. Well, you hear this a lot, but in fact for this one, it just isn't the case. You hear this a lot about swf from the svg crowd too -- which isn't correct either. You even hear this sometimes from Mac people about the PCs or .Net, which is very bizarre. Linux or BSD absolutely, but Macs? Weren't those 1984 commercials filmed inside the company?

I think number five can be boiled down to this: "Microsoft is popular. Popular is common. I'm special. I'm not common. Must boycott the man." The nutshell version is, "I don't like Microsoft". Ok, this is totally a valid way for a person to think, honestly no problem. I feel the very same way (emotionally not logically) about many other things, and it causes me to avoid them. However, it is important to separate these emotions from the pro's and con's of named constants or type indexers if we hope to move forward, or even just appear intelligent.

6) What about all the existing code for Java. What about the .Net framework. What about multiple language interaction, what about Eclipse or Tomcat, or Jakarta, or Jini, or Swing, or BulletFart etc etc. These are all valid points about the environment languages are used in, just not about the languages. Unrelated, but I'm not sure why computer people, and especially Java/Unix people, can't just name things for what they are. I guess everyone needs a little cuteness in their life, but why not name it 'XML Parser' and carry around a little pink kitty purse?

7) You can do anything in Java that you can do in C#. While that isn't very specific, in general that is right. There is the counter argument that even in an assembly language anything is possible, so language improvement is really important. While this is also true, it is pretty disingenuous to bring up in a Java vs C# debate. Programming is often a bit easier or 'safer' in C#, but not so dramatically that switching would be a 'slam dunk' proposition - even from J# to C#. The usual coder preferences, learning curves, project goals etc must be factored in, as always. When talking language though, it does come down to how you do things, so just 'being able' to do something doesn't mean much - you have to look at whether things like enums or properties make life better or worse.

8) Java 3.763 will kick C# 2.015's lilly white ass. This could be, I hope so even, as a programmer (from either side) that would only be a good thing. I'm sure they aren't sitting on their hands at Sun or IBM. There is lots of room for improvement in both (generics for one). Regardless of which will be 'best' in ten more years, but I'm certain both will be better. Of course this is also a different debate, but a good one.

Don't agree? No problem, but then you have to explain why it is better not to have enums, structs, indexers, properties, params, attributes, operator overloads, explicit virtual methods, ref, out, aliases, multiple classes per file, foreach, IDisposable/using, is, as, jagged arrays,verbatim @"strings", and preprocessor directives. Yeah, I'm sure I missed some, and I'm sure there a few the other way, but that is the jist.

End of major combat. Mission Accomplished!

posted on Saturday, May 01, 2004 7:17 AM
Feedback
  • # re: Comparing C# to Java
    Simon Barber
    Posted @ 5/1/2004 1:41 PM
    I totally agree that C# is currently a better language than Java but as you say we will have to wait until Java 3.763 arrives.

    BTW, nice article i really enjoyed it.

  • # re: Comparing C# to Java
    Simon Barber
    Posted @ 5/1/2004 1:41 PM
    I totally agree that C# is currently a better language than Java but as you say we will have to wait until Java 3.763 arrives.

    BTW, nice article i really enjoyed it.

  • # re: Comparing C# to Java
    Sean Corfield
    Posted @ 5/1/2004 4:18 PM
    You've done a good job of highlighting many of the totally specious comparisons people try to make - you're right that those eight issues: they have nothing to do with whether one *language* is better than another.

    However, as someone who really doesn't know C# very well at all, I'd be interested in some point by point comparisons of where the languages differ and where you think C# is better. Looking at your list of "pros" for C#, I'm not sure that I agree some of those are "good things" but I'd need more background to understand them.

  • # 
    Carlos Rovira :: Flash MX 2004-
    Diseño y Desarrollo de Aplicaciones Dinamicas de Internet :: ?.NET o Java?
    Pingback/TrackBack
    Posted @ 5/4/2004 7:16 AM

    Carlos Rovira :: Flash MX 2004-
    Diseño y Desarrollo de Aplicaciones Dinamicas de Internet :: ?.NET o Java?

  • # Some somewhat unique C# features somewhat explained
    Robin Debreuil's Blog
    Posted @ 5/5/2004 4:00 AM


  • # re: Comparing C# to Java
    Bent Rasmussen
    Posted @ 5/5/2004 9:20 AM
    Its just a matter of definition of "better". I'm not sure everyone confuses technical and political points - "better" may refer to the final decision of what to choose.

    Indexers. Aren't they only syntactic sugar? I like sugar, but still. Enums, nice. Properties, much better than get/setProperty names. Explicit virtual methods, yep nice too.



  • # re: Comparing C# to Java
    Robin Debreuil
    Posted @ 5/5/2004 3:58 PM
    Yeah, I totally agree Bent - in fact for 'what to choose' I would only put about 2% of the weight on the language. Way more important is the platform it runs on, the skillset you have/want, available libraries etc. Just I find C# often gets dragged in anyway, but maybe I just needto hang out in different places ;).

    I agree indexers are sugar, but to me they are 'sweeet'. Oh lord help us, a pun. When you have any kind of collection with some customization, it allows you to treat it the same way you treat an array. It also you to cleanly separate the backing store (because indexers are actually just accessors).

    For something like a hashtable, rather than have someone lock on to the ever changing keys array, or have some non standard method like Lookup, you can just access values with array syntax (like you do with actionscript) myhash["key"]. Strings are another one I like, where you can just use an index to access char[x], instead of all the substring junk.

    I don't often create indexers for my own class (other than codegen'd type safe collections), but use them all the time on classes built in to the framework. For some things though, like edges in swfs, they made the code way cleaner.

    The docs could be a little clearer in some cases when things have indexers, I remember at one point doing all kinds of backflips with the Keys array in hashtables trying to get a value. Enums too for that matter - I used to always go through the Enum Type to get the numeric value or string representation of an enum, where you can simply cast (int)Color.Red or use ToString(). Oh well, live and learn!


  • # re: Comparing C# to Java
    proJava
    Posted @ 5/7/2004 7:12 PM
    http://www.javasig.com/Archive/lectures/JavaSIG-Tiger.pdf

  • # re: Comparing C# to Java
    Jin
    Posted @ 12/6/2004 6:11 PM
    Of course I agree, are you crazy? Well, only very political people object to the fact that C# is better than java. Oh the library is even better. On the web asp.net is better than JSP. Where is Java better? Hmm, I would say cross-platform support, but then mono is there. But mono doesn't support winforms yet, ok, but it will within a year. But then, Swing sucks more than anything in world. So I don't see how java is better, but I wouldn't complain that we are using java in a project. Java is a good language too, but I would prefer C# for almost every project, except those which require me to run on Unix etc...

Blog Stats

  • Posts - 125
  • Stories - 1
  • Comments - 1441
  • Trackbacks - 47

.Net Blogs

01101 Blogs

Flash Blogs

Graphics

People