6 ms·
Fundamentally, Java and C# are extremely similar. What's interesting is how different their philosophies are: Java really values backwards compatibility, does n
by tikhonj 14y ago
Fundamentally, Java and C# are extremely similar. What's interesting is how different their philosophies are: Java really values backwards compatibility, does not evolve very fast and tries to hide and features that could cause a programmer to shoot himself in the foot. C#, on the other hand, has had some compatibility breaking changes, has evolved quickly with fancy research features (e.g. Linq is actually much like a monad with SelectMany as bind) and has a bunch of "dangerous" features like operator overloading and unsafe regions.
EDIT: Maybe there weren't actually any language changes breaking backwards compatibility. I'm not sure.
I personally like C#'s philosophy better: PL research exists for a reason and newer features make coding easier; moreover, I can avoid doing really stupid things and so can be trusted with operator overloading! Others maintain the opposite and believe Java's more conservative approach is best.
It would be nice to compare how the two philosophies fare in getting their respective languages adapted, but I fear such a comparison would be flawed: C# is much too tied to Microsoft, so most people not keen on heavy coupling with any particular vendor or OS tend to avoid it for that reason. The opposite is also true: heavy MS shops are much more likely to choose C# just because it's part of .NET, and not because of the language characteristics.
Still, it is very interesting to see what has happened given two virtually identical languages with different backers and philosophies.
- statictype 14y agoI'm curious: What are the breakages in backwards compatibility that C# introduced? The only one I can think of is the upcoming change in closure semantics for loop variables - something that is being changed to make it work like people would expect for 99% of the case and risks breaking that 1% of cases where someone actually wants the same loop variable to be closed over in all functions defined within the loop. (e.g. Linq is actually much like a monad with SelectMany as bind) Correct me if I'm wrong but I believe, with SelectMany, Linq does in fact, provide everything required to support monads. Agree with everything else you said - especially on flawed comparisons between the two languages.
- noblethrasher 14y agoInterestingly, named parameters introduced a kind of breaking change: http://blogs.msdn.com/b/ericlippert/archive/2011/11/07/breaking-changes-and-named-arguments.aspx http://blogs.msdn.com/b/ericlippert/archive/2011/11/07/break...
- deleted 14y ago[deleted]
- tikhonj 14y agoI'm not actually intimately familiar with C#. I remember reading about some of the changes between major .NET version (e.g. 2 to 3) which did not maintain backwards compatibility. However, on review, that may have been backwards compatibility of the bytecode rather than the language proper, in which case I am mistaken. It would be great if somebody who knows one way or the other for sure chimed in.
- josteink 14y agoC#3 adds features not found in C#2 (just as C#2 added features not found in C#1). However the C# compiler will produce bytecode compatible with the .NET 2.0 runtime from C#3-code. And all C#2 code will compile just fine with the C#3 compiler. Basically what breaks is trying to shove C#3 code through a C# 2 compiler, and that can hardly be said to surprise anyone. The part which may be confusing is that unlike Java and the JVM, C# is tied to CLR runtimes, and you can have several installed at the same time. C#1 was tied to the .NET 1.x runtime. C#2 was tied to the .NET 2.x runtime (which also powered .NET 3.0 and .NET 3.5). C#3 was tied to the .NET 2.x runtime with some extra LInQ DLLs installed (aka .NET 3.5). C#4 (which again adds more features) depends on the .NET 4.x runtime. And all these runtimes can be installed at the same time. The fact that Microsoft is willing to "leave old runtimes behind" and create new ones when the language features being requested requires it means they can iterate much faster than the Java can, since backwards bytecode compatibility is not required. I think it is a decision which has worked out largely to their advantage.
- kenjackson 14y agoI don't think there was much backwards compatibility breaks, but in generics C# broke forward compatibility of the bytecode, whereas Java didn't (they used type erasure for their generics). With that said, C# almost always breaks forward compatibility. It seems like a somewhat odd design goal to have for a language nowadays.
- bad_user 14y ago[Java] does not evolve very fast While this is true for Java the language, it's not true for Java the VM, which evolved a lot faster than the CLR. And because Java the language does not evolve very fast, the ecosystem has given birth to mature JVM compilers/interpreters for languages such as Clojure, Scala, JRuby and Groovy, amongst others. The biggest difference between Java and .NET is that the "backers" of Java come from a really big and open-source friendly community.
- kamaal 14y agoFor most part of the programming world, Java is synonymous with, Java the programming language, not JVM. I always thought Java went very heavy on the frameworks side. Evolution was faster on the frameworks end.
- bad_user 14y agoI think it's irrelevant what people associate Java with, as long as its success can be attributed partly to the awesomeness of the JVM. There's no other mainstream VM out there that does the optimizations that the JVM is doing, or that has the awesome garbage collectors that the JVM has. Have you seen the details of the new Java G1 garbage collector or the specs for JSR-292 (InvokeDynamic)? That's awesome evolution right there.
- kamaal 14y agoI am not saying JVM isn't awesome. But JVM isn't anymore about Java, than JavaScript is about Java. Its like calling the Pentium/AMD/ARM as C processing Machines. The name is deceptive, JVM based languages gives an impression that the languages have to do some thing with Java. Sure they have Java interoperability, but that is different to liking them them with the 'Java programming language' brand. Since JVM was shipped to run Java programs, it was called Java virtual machine. Otherwise its a virtual machine optimized to run Java programs. When people think of Java its 'Java the language'. JVM improvements are not necessarily improvement on the Java programming language syntax and semantics.
- 14y ago
- moomin 14y agoI think the differences between C# 1 and the current Java have been rather downplayed by this discussion. C#1 was different from Java in a number of very important ways: * You could call directly into the Win32 API (the issue that caused Sun and Microsoft to fall out) * Value Types. Still being discussed for v8. * Lambdas. Yes, in version 1. * C# had enums, Java didn't. (Now Java has better enums than C#) * A syntactic sugar for property get/set. This was extremely important to Microsoft. * A decent COM-interop story. Again, very important to Microsoft. Of course it was similar. It was a design goal to be able to run Java code on the .NET VM. But it was far from identical. Jon Skeet could no doubt expand this list
- dbattaglia 14y agoI'm not so sure about lambdas in v1. I remember v2 added anonymous functions ( ex " delegate(int x){...}" ), and real lambdas not coming until v3.
- moomin 14y agoYou're correct, anonymous functions were 2.0, sorry. However, I'd argue that, syntax aside, they were already true lambdas. The expression stuff that V3 added isn't even on the Java roadmap.
- SiVal 14y agoThere's no big mystery. I was there and saw it all happen. Java, the language, hadn't made any progress for several years. Programmers like me would complain at Java user group meetings here in Silicon Valley that we wanted certain features in Java (enums, lightweight structs, etc.) and the Java guys from Sun would always do an Apple on us: you don't know what you want. You're not experts; we are. We know what you really need better than you do, because we're smarter than you and have better taste, so trust us, you don't really need <whatever features we were asking for>. There was always a Microsoft rep at those Java user group meetings. After the meeting, he would come up to us and ask us again what we wanted and why. Unlike anyone from Sun, he'd ask good questions, listen carefully, and take notes. Microsoft genuinely liked the language as a much-better C++, but wanted it to have native extensions on Windows for two reasons: 1) it would encourage the writing of code that would be less portable, thereby reducing the threat to MS's advantage of being the platform with the most apps, and 2) apps written in "pure" Java just weren't as good as native apps, and for Java to become the "better C++" that many programmers inside MS were hoping for (for their own use), it was becoming clear they would need native extensions. MS tried to produce a Java with native extensions: Visual J++. Sun filed suit, claiming that MS was in violation of contract. I don't recall the outcome of the suit, because MS decided that Java's slowing acceptance as a general-purpose language for client-side apps (and part of that slowness was CAUSED by MS) meant that there was less need to claim support for Java. It wasn't going to take over the world after all. (Steve Jobs later made the same decision). Not supporting it wouldn't mean you would be left behind. They abandoned Visual J++. Instead, MS wanted their own Java-like language with no strings attached. Java was a trademarked name, so they created a language with a different name but all the Java features (LANGUAGE features) that programmers liked so much, plus most of the features that Java programmers were begging for that Sun was sniffing at, plus the native extensions needed to write Windows apps that would only run on Windows AND would run so well they would, in general, be indistinguishable from native apps written in Visual C(++), and they built a great app builder (VC#) to go with it. They did a beautiful job with Visual C# and rattled Sun so much that suddenly a lot of those "impossible" features we "didn't need anyway" became available in Java, but C# has always maintained a healthy lead over Java in nice features for client-side programming, IMO. (And Java has maintained a superior overall adoption rate, especially on servers.)
- 14y ago