9 ms·
Why Java folks should stop looking down on C#: differences in similarities
- rudiger 15y agoIt'd be tough to argue that Java is better than C# (the programming language). The benefits of Java come not from the programming language, but from the ecosystem, the JVM, the libraries, and the platform.
- InclinedPlane 15y agoTo be honest, I'd say a lot of the java ecosystem exists to make up for failings in java itself. A lot of other languages are just plain better out of the box with either more robust built in features or language design that avoids common problems. For example, C# doesn't need the equivalent of spring and hibernate because there are equivalent, or indeed superior, built in or 1st party options in the form of LINQ and asp.net mvc. Similarly, there's less need for 3rd party build tools like ant because msbuild is available right out of the box.
- squidsoup 15y agoI think you mean LINQ to SQL rather than LINQ - LINQ is a query language, not the ORM/provider. Last I heard MS were trying to deprecate LINQ to SQL in favour of the entity framework. In practice a lot of developers end up using open source build tools like nant and rake in preference to msbuild as they tend to be more flexible in other build environments like TeamCity/Hudson.
- tzs 15y agoConsidering that for the last several years nearly every significant improvement to Java has come from them copying from C#, if anyone should be looking down it is the C# folks.
- currywurst 15y agoExactly ! In fact, I know of people (myself included) who look at C# in envy ! I think Microsoft has managed the language really well, even taking painful decisions like backward-incompatible versions to properly support generics. Kudos to the team !
- henrikschroder 15y agoI've been working in C# for the last five years or so, and I couldn't ever consider going back to Java again, every time I look at some code, even my own, I just see all the nice things that are missing. There is so much that might seem like syntactic sugar at first, but when you get into it, you can just express yourself in a lot less code compared to Java. Sadly, there also seems to be a culture thing around Java to make things needlessly complicated, whereas the culture for C# is about writing less.
- jimbokun 15y agoI've started using Jython along with Java at work to get some of the syntactic niceties described for C#. But it would be nice to get the syntax without having to cross language boundaries.
- nagnatron 15y agoCopying? Most of the stuff is pretty old and invented elsewhere anyway.
- code_duck 15y agoPardon my misunderstanding, if there is one, but didn't C# start as essentially Microsoft's clone of Java? Seems if Java wants to return the favor, it's fair enough.
- eropple 15y agoNo; Microsoft's clone of Java was J#, once J++. C# has some shared ideas but pretty dissimilar behaviors.
- 15y ago
- SemanticFog 15y agoIf Java could be redesigned from scratch, with no concern for backwards compatibility, it would probably look a lot like C#.
- Locke1689 15y agoIndeed. Java, from the programming language design standpoint, has made some very poor decisions. The following come to mind immediately: * Lack of first class functions * 'null' type C# has fixed both of those.
- quanticle 15y agoMore to the point, C# has integrated an excellent map-reduce framework in the guise of (P)LINQ. Java still doesn't have anything analogous to that, nor does it plan to, if the latest roadmaps are any guide.
- squidsoup 15y agoI'm not certain that Java really needs this. Developers that wan't a more functional style should consider making a transition to Scala or Clojure. Scala can evolve at a much faster pace than Java as well, given that the core language is tiny and most of the language constructs are implemented as libraries.
- StrawberryFrog 15y agoI'm not certain that Java really needs this We weren't certain that C# needed it. Until we tried it.
- runevault 15y agoHe didn't say they weren't useful, just that Java the Language doesn't need it, due to the fact other languages that have interoperability with Java on the JVM have these features already. .NET isn't as language rich as the JVM currently unless I missed some major changes.
- old-gregg 15y agoSome Java folks are looking down on C#? I don't believe it :)) In my experience it's always been the opposite: C# guys have always looked down on Java folks. And rightfully so: the language itself is nicer, the standard library is much nicer, and the CLR+CIL are vastly superior to JVM, especially in memory management department.
- ronnier 15y agoI was a C# guy before I took a job at Amazon where I do a lot of Java. I prefer C# but don't mind doing either. They both get the job done.
- factorizer 15y agoand, last but not least: excellent multi platform capabilities! think aix, solaris and the like. you name it!
- zbowling 15y agomono
- hristov 15y agodoes not work
- thepumpkin1979 15y agowhy do you say it doesn't work? It does work... is just that Mono is mostly used in Linux and OSX.
- hristov 15y agoAnything I have tried to use Mono for has not worked. Maybe there is a subset of of .net stuff for which Mono works perfectly, but I do not think we should say that .Net or Silverlight are cross platform based on an incomplete Mono implementation.
- deleted 15y ago[deleted]
- Niten 15y agoToo bad he didn't get into any of the stuff that really makes C# nicer than Java, in my opinion: lambda expressions and closures, LINQ, expression trees, dynamic typing, type inference, P/Invoke vs JNI. Also the event / delegate thing makes C# really nice for GUI stuff.
- SeanDav 15y agoIf you read the small print you will see that his next blog post is going to be about exactly that!
- Niten 15y agoOops, thanks... missed that last paragraph there.
- przemelek 15y agoP/Invoke is worst part of C# ;-) In Java JNI, and even JNA are difficult to use for purpose. So if you really need native code you may use it, but it is difficult to do, thanks to this most of developers never used anything native. In C#/.NET P/Invoke is so easy that almost all projects are using it. But this makes those project Windows only, this result in all problems with things like scalability or being bound to one vendor. In case when you need to move your app to other system it will cost a lot, and results aren't sure. With Java moving app to another system is quiet easy, I was moving some apps from Windows to state when those apps are able to work on Windows and *nixes and this was rather easy, you need only to be careful with working with files. And because of this most of big Enterprise projects are on Java, not on .NET. Maybe Java isn't the best language on Earth, but JVM and this what is behind JVM is (as for now) the most Enterprise friendly platform on the planet ;-) This that behind Java you may now two big vendors, so Oracle and IBM, and behind C#/.NET you have one - Microsoft ale makes difference. You are right C# is nice for GUI stuff, but... but again only for Windows, not even for mobile, because as for now WinMo is far behind iOS and Android... and you may use Java on Android, and BlackBerry ;-)
- guard-of-terra 15y agoAfter reading about "Explicit virtual methods" I lost all my interest in C# forever. I don't want this, seriously do not want. I don't want a language "with lovely features from C++". Explicit virtual, structs - please take those and leave me alone. Lambdas are nice, some syntax sugar is nice, but not that creep. Please don't take this as flamebait. I know a handful languages, I do backend development and I just absolutely don't need some language features and I fear that somebody would use them in their little library and would POISON the lifes of anybody who touches it. Java has some "do not want" features too, like checked exceptions, but those are more or less solved these days.
- 911-inside_job 15y ago>> After reading about "Explicit virtual methods" I lost all my interest in C# forever. Hmmm? Is it so hard to type "virtual " in all your method and properties (if you don't care about the performance)? Also all virtual methods have to be considered a part of the API exposed by a class. So non-virtual by default is not THAT bad.
- sukuriant 15y agoYou're not the only person in that position. I'm a developer from the Java camp and moved over to the C# camp (by work necessity, Oracle, etc); and, of all the features of C# that I enjoy (Properties, Attributes, Lambda expressions, etc.) I absolutely abhor the idea that I, as a developer, have to know, perfectly, what future subclasses are going to want/need to run properly. It has never made sense and always felt like it was taking away one of the core tenants of object orientation (though I know that neither Java nor C# are true-OO languages). I know it probably technically doesn't, but that's how I've felt ever since I heard about doing it "another way"
- teyc 15y agoAs a library developer, you can explicitly declare all your methods as overridable. The key point is that in large scale software development, in Java, you can have the following undesirable situation: Version 1, you import a third party library: public class ThirdParty { public void calculateAndPrintResult() { System.out.println("1"); } } public class Mine extends ThirdParty { public void calculateAndPrintResult() { super.calculateAndPrintResult(); this.printResult(); } protected void printResult() { System.out.println("2"); } public static void main(String[] arguments) { Mine mine = new Mine(); mine.calculateAndPrintResult(); // Prints 1, 2 } } Version 2, third party has refactored and introduced printResult. You swap in the new third party library and suddenly the behavior has changed: public class ThirdParty { public void calculateAndPrintResult() { this.printResult(); } protected void printResult() { System.out.println("1"); } } public class Mine extends ThirdParty { public void calculateAndPrintResult() { super.calculateAndPrintResult(); this.printResult(); } protected void printResult() { System.out.println("2"); } public static void main(String[] arguments) { Mine mine = new Mine(); mine.calculateAndPrintResult(); // Prints 2 ! (wrong) } } While this example is trivial, bear in mind, when you have programming in the large, i.e. large codebases with a lot of third party libraries and many teams of developers, you would rather not have surprises like this pulled on you, or you pulling surprises like this on other people. It can take a lot of work tracking down this kind of bug. When you finally realize this type of issue arises despite everyone following "best practice" OOP, then the reason is because "best practice" OOP is not actually best practice.
- teyc 15y agoCredit has to go to Anders Hejlsberg, who keeps innovating upon C#. Microsoft in this case has played to their strengths because 1) it does not have to worry about language standardization and the various community processes that accompany Java. 2) Anders is exceptionally good at deciding what language features are go/no go.
- ppog 15y agoNitpick: You're right that the C# designers don't have to worry about a JCP-like standardisation process, but they do put some effort into producing a formal language standard (I think through ECMA). Unlike earlier Microsoft proprietary languages, where the language definition was whatever the compiler said it was, the C# team do try to pin it down, make sure all the edge cases are considered, and so on. The compiler implementers try to write to this spec. They don't always succeed, but from what I read on compiler guy Eric Lippert's blog, when they do diverge, he regards that as a bug in the compiler, not an error in the spec. That said, the standard is very much owned and written by Microsoft. You're absolutely right that they don't have to work through a JCP-like process.
- teyc 15y agoYes, you are right. Despite it's proprietariness, C# enjoys having team that is very rigorous and have a great deal of compiler experience. Eric Lippert is super cool. In fact, C# remains one of the reasons why I still root for MS.
- meow 15y agoSadly, Microsoft is one of the reasons C# isn't living up to its full potential. If they would release an official version of .NET for Mac, Linux or at least officially support Mono project in a more decisive way, C# will become a lot more popular. I don't think they gain anything by this though (apart from Moonlight which lets them advertise platform compatibility), which is why they will never do this :(
- teyc 15y agoEven though MS is a large money making behemoth, I don't necessarily think C# would be served any better by MS trying to support other platforms. A large part of .NET depends on a well supported class library. These class library can be very operating system sensitive. Backslashes vs forward slashes, directory separators, nonblocking IO, GUI stack etc. It is hard to do this well. Particularly on a platform that belongs to your competitors. Microsoft has pushed Silverlight as a .NET vm that runs on Mac, with a smaller framework library. So far, this has met will little traction. I don't think it will encourage MS to push this further and wider.
- _Daniel_ 15y agoThe author makes some fair points. Java generics are a bit clunky. C#'s more liberal application of autoboxing can be nice. Some other options for string literals would be helpful, especially for writing regular expressoins without a ton of backslashes. Checked exceptions are not something that I'd happily give up. We do have unchecked exceptions (RuntimeException), and the JRE generally uses them where appropriate. But what about methods like Inflater.inflate, ImageIO.read, or Class.getMethod? If these didn't throw checked exceptions, we would sometimes forget to catch exceptions which should almost always should be caught. It would be a step in the direction of a weaker type system, unhelpful errors, and less graceful recovery. Regarding initializers, we can do the same thing in Java by giving an initializer block to an anonymous class: List<Integer> L = new ArrayList<Integer>() {{ for (int i = 0; i < 10; ++i) add(i); }};
- StrawberryFrog 15y agoEquivalent code in c#: var l = new List<int>(Enumerable.Range(0, 10));
- thepumpkin1979 15y agoDelegates + Events are another innovation in C#, is a much cleaner approach than Java anonymous classes + interfaces IMHO. I think anonymous classes are good in both compilers but Java is really missing a delegate/event standard system.
- MartinCron 15y agoOnce you hit a particular point in your personal/professional development, you'll stop looking down on just about everything.
- jhpriestley 15y agoI always enjoy these Java vs. C# threads. They are like dispatches from a world where there are only two, absolutely terrible, languages. It makes me happy that I live in a world where I can choose between dozens of languages, some of them actually decent.
- jschrf 15y agoSuprised that reflection wasn't really mentioned outside of the concept of generics. Reflection in .NET (and C#) is extremely powerful and useful. All those other things that people have already commented on like Lambdas, expression trees, events and delegates, are incredibly nice to have. Here's the first thing I write when I start a Java project, followed directly by an abstract class based on it: public interface ICallback<T> { public void Invoke(T state); }
- lurker19 15y agoDoes that give you something better than Fuction<T,V> (aside from not requiring a return type)? http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Function.html http://google-collections.googlecode.com/svn/trunk/javadoc/c...
- binaryfinery 15y agoFTA: "both are designed with runtime compilation in mind" vs "and interpreted, for maximum portability and dynamic capabilities." from Design Goals for the Java Programming Language http://java.sun.com/docs/white/langenv/Intro.doc2.html http://java.sun.com/docs/white/langenv/Intro.doc2.html