14

Please note that this isn't meant to be a Java vs. C# argument. I'm a Java programmer with no C# experience, asking just out of curiosity.

I did some reading on C#, and it seems it has much more features than Java. A number of examples:

  • Type inference.
  • dynamic keyword.
  • Delegates.
  • Optional parameters.
  • Lambda and LINQ (I actually have no idea what these are).
  • Properties.

However Java doesn't really feature anything that C# doesn't have.

My question is: why does C# have much more native features than Java? And why didn't Java add some of these throughout the years, for example Properties or type inference? Do the Java language designers take a more simplistic approach? What is the reason for this?

15
  • 2
    @Patrick - Is that a feature - or an implementation detail?
    – Pete
    Jul 3, 2014 at 9:56
  • 14
    Biased answer: Because the C# design team know what they're doing. More reasonable answer: C# was designed with the knowledge of Java's failures and without the dogmatic "only pure OO" (that they didn't even quite hit). Half of those features were bulk-imported from Lisp and Haskell, two languages Java steadfastly refused to be inspired by until java 8, and the others are sanity improvements made blindingly obvious by Java's lack of them.
    – Phoshi
    Jul 3, 2014 at 9:57
  • 4
    Because C# came later and was initially a blatant rip-off of Java, and then had the opportunity to add everything that turned out to be worthwhile in addition, while Java was hampered by very strict backward compatibility goals. Jul 3, 2014 at 10:02
  • 2
    @Clockwork-Muse but C# has two runtime implementations - CLR and Mono. Also there is Xamarin. I have not heard of a single solution for building cross iOS/Android/WinPhone projects using Java.
    – Den
    Jul 3, 2014 at 13:14
  • 4
    @KilianFoth: Actually, C# was initially a batant rip-off of Delphi, rewritten to look like Java. Microsoft even poached the Delphi project architect away from Borland to create it. Jul 3, 2014 at 15:42

2 Answers 2

23

Several reasons:

  1. C# came later than Java; version 1 was a blatant rip-off of Java 1.4, so it pretty much had everything Java had at that point.
  2. But then C# developed much faster than Java, because it was an exciting new platform (and had an utterly brilliant driver in Anders Hejlsberg, the father of Turbo Pascal). That allowed them to avoid all the mistakes in Java that had become obvious, while adding everything that Java practitioners wished they had.
  3. Meanwhile, Java was hampered by very strict backward compatibility goals and by a somewhat slower pace of development, partly because it tried desperately to gain a reputation for being the standard, enterprisey, reliable, non-surprising solution for the 95% of non-genius programmers. At this they succeeded, perhaps a bit too well.

The result is that Java now has a bit of a feature gap. It does have huge plans for the future, but as usual with this sort of thing everything takes a bit longer than planned.

8
  • 7
    I'm not sure I agree with this. I mean it's all true, but I suspect that the reason has more to do with the politics around the collapse of Sun. Java basically had 5+ years or so where there was no organization/leadership - so there were no new features.
    – Telastyn
    Jul 3, 2014 at 11:45
  • 7
    C# 1 had value types. Something that Java will never have. So not just a "blatant rip-off".
    – Den
    Jul 3, 2014 at 13:15
  • 1
    @Telastyn -- I think that is the single most important reason here. Especially when you add "and then you get acquired by oracle" to the end of the Sun collapse. Jul 3, 2014 at 13:18
  • 7
    Agree with @Den. I think the biggest reason for C# developing faster (and in the right direction) is the leadership of Anders Hejlsberg. He and his team have added the best features from other languages, and managed to integrate them seamlessly into C#. The result is that C# has very neat language features without feeling cluttered or messy. Jul 3, 2014 at 14:12
  • 1
    @WesleyWiser - upgraded to "might have in future".
    – Den
    Jul 7, 2014 at 21:18
4

I would add to Kilian's answer that one big difference between Java and C# is that C# designers control not only the language, but also the standard IDE.

Adding something like extension methods and partial classes could be a nightmare in development/control versioning if the IDEs would not properly support it.

Since you are expected to be able to compile Java with your platform of choice (Eclipse, Netbeans, vi + Ant), adding features that break the code (and using these to develop additional extensions like LINQ) is way more complicated than just saying "since IntelliSense will deal with these cases, we need not to worry".

Additionally, sometimes it is worth noting the value of the features instead of its number. For instance, automatic properties are nice and I certainly wish Java supported this, but in the end it only means that you have to write a few more lines of code in Java. Similarly, I find that calling "Events" a feature is somewhat of a misnomer, since they are little more than specially labelled delegates, and just a refined copy of the Observer pattern already used by Java (then again, in Java it needs more explicit coding)

Don't get me wrong, I think C# has introduced several noteworthy innovations, and I wish that someday Oracle big bosses will wake up and launch a true "Java 2" to include some of these, but the gap is not as obvious as your question points.

5
  • 2
    The nine lines needed for a simple property definition (declaration + get/set + white space) add up quickly to more than "a few". Jul 3, 2014 at 16:13
  • @kevincline and I also document properly both setters and getters. But in the end, even if I am not using my IDE automatic code generation for the accessor, I am not using any noticeable amount of time with these, when you factor in the time spent in business logic, testing, code design (in fact I am mostly thinking about these even when typing the accessors). So, while nice, it is not something that makes a great difference in the end...
    – SJuan76
    Jul 3, 2014 at 16:26
  • 3
    It's not the time to write them. It's the time to read and ignore them, over and over and over and over again, while you are on your way to the interesting parts. Jul 3, 2014 at 21:04
  • @kevincline I agree, it's abiut readability and the code being clean. This is why I value things like Events, which are just a built-in Observer pattern, but make things much cleaner thab if you had to write these yourself
    – Aviv Cohn
    Jul 6, 2014 at 11:38
  • @AvivCohn The thing is, "built-in" is the key part. You can have dynamic dispatch in assembly, you can have higher order functions in C, every single language feature you can have is possible in assembly - obviously, since at some point, it still runs on your x86 CPU. You rarely need to implement the Command pattern in C#, because you have delegates. The same with Observer and events, and many others. Java had anonymous methods for some time, but you had to create a whole anonymous type. All those things are tiny, but they add up.
    – Luaan
    Jan 25, 2016 at 10:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.