8 ms·
C# is now a better language than Java
- fogus 17y agoIt's fashionable to say that Java is painful to use, and there is truth to the statement. However, when I started with it I had come off of a few years of C++ and loved that it reduced my pain exponentially. Like the new lover's quirky laugh, the 'nuances' of Java became annoying. It almost seemed as if with Java there is a threshold of productivity that the language itself imposes. I have since moved on to Scala/Clojure and again feel renewed. Maybe that is the natural progression of programming languages?
- icey 17y agoI see C# as a linear improvement on Java. In my eyes, it looks like this: C++ --> Java --> C#
- shin_lao 17y agoC++ has got nothing to do with neither Java nor C#.
- logicalmind 17y agoThe majority of Java/C# syntax was derived from C++. So I wouldn't say "nothing".
- rawr 17y agoAt least the OO parts. Of course the syntax was originally C.
- DrJokepu 17y agoThe C# ECMA Standard ( http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf http://www.ecma-international.org/publications/files/ECMA-ST... ) mentions it several times that one of the main design goals of the C# language was familiarity to C++ programmers. Indeed C# borrowed a considerable portion of its syntax and keywords from C and C++. I suppose the same is true for Java as well.
- berntb 17y agoThe C# standards only mentions C/C++ and not Java?! >>Indeed C# borrowed a considerable portion of its syntax and keywords from C and C++. I suppose the same is true for Java as well. It seems really weird to me when you sound like C# was an independent development? I'm not an expert on either, but... Didn't Microsoft even try some (/a few?) Java-clone before C#? And then we have that "embrace and extend Java" thing Microsoft tried first. Is the ... hrm, inspiration... from Java in C# "the love that dare not speak its name"? :-)
- messel 17y agoha, I think so berntb.
- ido 17y ago> Didn't Microsoft even try some (/a few?) Java-clone before C#? J#[1]? J++[2]? [1] http://en.wikipedia.org/wiki/J_Sharp http://en.wikipedia.org/wiki/J_Sharp [2] http://en.wikipedia.org/wiki/Visual_J%2B%2B http://en.wikipedia.org/wiki/Visual_J%2B%2B
- berntb 17y agoThanks! Next time I'll just check this document linked from the J++ 'pedia page myself before asking. http://www.ecis.eu/documents/Finalversion_Consumerchoicepaper.pdf http://www.ecis.eu/documents/Finalversion_Consumerchoicepape... Page 16: Kill cross-platform Java by grow[ing] the polluted Java market. (Microsoft internal document.) Etc etc, with references. This document could be posted as a story on HN, if anyone wants lots of karma. :-) We can say one thing for certain -- the "love" here is criminal and violent...
- icey 17y agoI don't think you know your history very well: http://en.wikipedia.org/wiki/Java_%28software_platform%29#History http://en.wikipedia.org/wiki/Java_%28software_platform%29#Hi...
- shin_lao 17y agoBeing based on something doesn't mean it's like similar. Is C++ like Simula? My statement was probably poorly phrased, but what I meant is that a modern C++ program is nothing like a modern Java program. The approach are radically different. I'm thinking about what the heavy usage of templates in C++ allows, what you can accomplish in terms of generic programming. You can write in C++ like you would do in Java/C# but that would be pointless IMHO (complex hierarchy, virtual methods, etc. : exactly what I try to avoid). It's like saying lizards an birds are similar because they share a common ancestor (dinosaurs).
- sorbits 17y agoJava certainly evolved the OO parts of C++. C++ being a multi-paradigm language it does however have more than the OO stuff, and that “more” wasn’t inherited by Java. This “more” is things like operator overloading, templates, compile-time types (allowing implicit type construction and user type conversion operators), well-defined rules for automatic storage, etc. I rely heavily on these things and so does the IMHO elegant standard template library. I rarely use the OO features of C++ (if we define OO as inheritance and polymorphism, I do of course use data abstraction). I assume the parent is doing something similar, which is what makes him say that Java/C# has nothing to do with C++, as there was a crossroad a decade ago where a lot of C++ users moved away from object oriented programming and instead embraced generic programming.
- messel 17y agoOut of curiousity icey, where would these languages fall on your chart: ruby on rails? scala? python? I'm attempting to "download" web programming languages in an exceptionally short time but I'd prefer focusing on high end producers. I can see advantages and pains to various syntax and functionality, and have been fairly liberal in my choices so far to focus on existing libraries.
- stevecooperorg 17y agoFor me, they're different 'flavours' of programming and fit on a different chart. The C++/Java/C# line is for static programming with heavy reliance on a compiler -- the idea is that the compiler helps you find lots of errors. In all three languages, getting the program to compile rules out whole rafts of problems. Python and Ruby move that responsibility onto tests -- you run the code to find errors. I think C++/Java/C# fit onto a line, each taking away accidental complexity and adding higher level features. C# iterators and lambdas are a good example the OP mentions, of a high-level feature that makes possible styles not available in Java and C++. (we use C# iterators and lambdas to write in a more functional style than we could in Java)
- icey 17y agoMy "daily drivers" are C# and Python. I'm picking up Clojure right now, but haven't really done much with it - I really like lisps in general, but for some reason always fall back to either C# or Python when I need to write something I'm going to maintain. If I were in your shoes, I would start with Python and Django. It's a good framework on a good language, and most importantly, Django has a very good community and almost peerless documentation that's available for free online. Ruby on Rails is also quite nice, I'm just not a big Ruby fan. There is no reason for this other than personal preference. Scala seems very interesting, but I personally don't see a gain in learning it (since I have C# in my toolbox). Your mileage may vary. For whatever it's worth, everyone I've dealt with seems to have had a pretty painless transition from C++ to C#. I am not a Java person, so I can't really speak to that.
- known 17y agodata types < data structures < design patterns
- ramoq 17y agoI've always preferred Java to several languages (could be JVM influenced). I would still rather hack up an idea using Java vs C# or many other languages.
- umjames 17y agoWhat are the other languages that you prefer Java over?
- DrJokepu 17y agoOne example is COBOL which was (and is still being) largely replaced by Java in the business application market and rightly so. Even if you don't like Java, you have to agree that it's a great replacement for COBOL.
- jff 17y agoVerbose... favored by mediocre programmers... loved by business types... you're right, Java is the new COBOL!
- DrJokepu 17y agoI think you're being harsh on COBOL. Clearly, it is a thriving language that's being kept up-to-date according to the latest trends. Check the out the COBOL Ruby on Rails equivalent, COBOL ON COGS if you don't believe me: http://www.coboloncogs.org/INDEX.HTM http://www.coboloncogs.org/INDEX.HTM
- AlisdairO 17y agoI've never really understood why verbosity was that big a deal. I could very easily type the code that I write per month in a single day. A bit of extra time typing for a more verbose language has very little effect on my output. I don't know if that's an artifact of the type of code I write (quite algorithmic, so large periods of sitting and thinking followed by a bit of writing), but it's just never seemed much of an issue to me on a practical level.
- DanielStraight 17y agoJava is painful after experiencing .NET. I'm not sure this is really news though.
- habs 17y agoI wouldn't describe it as painful myself. But, I would agree with sentiment. Having spent 3+yrs working with Java and then moving to C# (2yrs+ dev) has been a pleasant experience. C# is great language with features like delegates, Indexers, Pointers and Unsafe Code (executed in an unsafe context) and constraints on type parameters. In contrast, I hate the msdn documentation for C# and still have a soft spot for java documentation.And yes, C# v Java is not the same as JVM v CLR
- lunchbox 17y agoI hate the msdn documentation for C# Not sure if this is addresses your complaint, but MSDN's low-bandwidth formatted site makes it easier to work with. Example: http://msdn.microsoft.com/en-us/library/system.xml.xmlreader%28loband%29.aspx http://msdn.microsoft.com/en-us/library/system.xml.xmlreader... Here's a link to a bookmarklet you can use to turn loband on: http://weblogs.asp.net/jgalloway/archive/2008/08/30/msdn-low-bandwidth-bookmarklet.aspx http://weblogs.asp.net/jgalloway/archive/2008/08/30/msdn-low...
- chaostheory 17y agoI think another thing I really hate about C# documentation is that it's merged with docs for other languages like VB.NET. It's a small thing but when I need to do something, I really don't want to be wasting time constantly filtering through stuff I don't need.
- Rexxar 17y agoThere is a language filter in order to display only language we want to see (in the standard version, not the low bandwidth one).
- francoisdevlin 17y agoExcellent writeup, and he nails the fact that C# vs. Java is not the same as CLR vs. JVM.
- solutionyogi 17y agoInteresting. I don't think it's right to discount the CLR and focus on the language whereas the fact is that C# can not do certain things without support from CLR. [In fact, for each C# feature, I like to know whether it's a compiler trick or CLR feature.] The biggest example I can think of is 'generics'. Java 'generics' are implemented using the compiler and JVM has no clue about them whereas CLR actually understands them and you get full reflection support for generic classes. Read this detailed article on Generics in Java vs C#: http://www.jprl.com/Blog/archive/development/2007/Aug-31.html http://www.jprl.com/Blog/archive/development/2007/Aug-31.htm... I also like the utility of AppDomains supported by CLR. Overall, I love .NET platform precisely because how all the modules (CLR, languages) are integrated with each other to give you a powerful tool set. Other than JVM being portable, I don't know of a single case where JVM is superior to CLR. [Performance wise there is not a measurable difference between the two.]
- snprbob86 17y agoThere is no reason why you can't implement a C# compiler which uses the same compiler "tricks" as Java. In fact, someone has: http://www2.mainsoft.com/content/port-net-apps-java-ee http://www2.mainsoft.com/content/port-net-apps-java-ee (I've never used that software and can't say if it really works as promised, but I don't see why not) Which side of the fence the compiler/runtime fence any given feature fails on is probably more a function of (human) resource pooling on the Microsoft managed languages teams than any technical constraints.
- solutionyogi 17y agoThat's COMPLETELY incorrect. I have been following blogs of CLR team and C# compiler team members and they think very hard about whether a feature needs to be a compiler feature or in the runtime itself. If they are short on manpower, they don't implement a feature rather than implementing it at the wrong level.
- mgrouchy 17y agoI am not sure if I feel it is better, but I do like them both quite a bit. Sometimes I just feel like C# is just a little bit more pliable in a lot of ways compared to Java, just a little easier to make it do what you want it to do.
- kashif 17y agoWindows usually undoes that benefit really fast...
- mgrouchy 17y agoyou could use mono....?
- shimi 17y agoI wish Mono would be even half as good as the .NET, I really do!! I actually had great hopes for the .NET Compact Framework until the Dalvik came along...
- stevecooperorg 17y agohow so?
- angstrom 17y agoI could tell the tipping point when I did a recent search for jobs. Even NYC which is still heavily Java is shifting to C#/WPF for client front ends.
- StrawberryFrog 17y agoWhat do you mean, now ? annotations (though C# calls them "attributes") he means "Java added attributes, which C# had from day 1, but called them "annotations"" C# has many of the same features as Java ... generics Again, C# had this first, and still does it better since the bytecode is aware of them.
- adharmad 17y agoJava being more widely deployed has to worry about source and binary compatibilities between all the supported versions and thus for them, changing the bytecode would have been a painful decision. As opposed to that C# did not have to worry about these things due to their limited deploy base and could freely change the language and/or the VM without worrying about backward compatibility. That does not mean java is a better language than C# - its just that when Sun woke up and started adding features to the language, it was not easy.
- likpok 17y agoI belive that was the original reasoning, and thus led to the Java generics behaving a little weirdly. Then other decisions forced them to change the bytecode anyway, but they never fixed generics.
- cakeface 17y agoActually it does mean that C# is a better language now. If you are developing new applications then all the compromises that were made to shoe horn in new features don't matter to you. You just want something that works well and is simple. I think that C# has that on Java in a lot of respects.
- adharmad 17y agoNo arguments there. But the rate at which C# is changing, what is stopping Microsoft from adding yet new features and breaking compatibility with previous language/VMs?
- 17y ago
- subwindow 17y agoHe's just now realizing that Java is painful to use? Even PHP had me dreading the tiny bits of Java work I had to do when I last touched it in 2005.
- mahmud 17y agoThe SLW in me thinks: "Don't choose a language for its features, choose a language for its feature building capabilities". It reminds me of people who buy stackable shelves and drawers to store their crap and make some room. Sometime later, they buy vacuum-sealable bags to store things that they bought after they made some space. As time passes, they start digging for a new basement and add another floor as an attic to store more things. Java vs C# programming sounds a lot like two hoarders of the kind described above, except one has enough room behind his La-Z Boy to recline to 120 degrees, while the other only gets to 100.
- messel 17y agowhere's the purist that lives outside on a hammock?
- endtime 17y agoYou mean the guy who made this web site?
- jrockway 17y agoIndeed. Java and C# are some of the least flexible programming languages around. The problem, though, is that people like being told what to do. They don't want to wonder if they are implementing something correctly, they want to know that they are "following best practice". They don't want to invent their own features, they want to read a cool blog post about something "the experts" came up with and then try using that in their application. This produces horrible code, of course, but since it sort of works and nobody knows any better, it's the norm. (Most programmers don't know programming. Why they want to be a programmer is beyond me, but it happens.) The people that have a deep understanding of programming and know what they want to do and how to do it are not using Java or C#.
- nollidge 17y agoC#'s got lambdas, closures, generics, reflection, extension methods (weak form of monkey-patching), and anonymous types (I can't speak to Java, but it's got a lot of these as well). Can you please describe the flexible features C# is missing? As for the programmers in those languages, I guess I'm one counterexample. My colleauges and I talk quite a bit about the "right way" to do things. We gripe a great deal about shortcomings in the .NET universe. I hate "best practices" (aside from trivialities like naming conventions), and prefer to evaluate practices on their merits. I've written frameworks of various sizes. I read cool blog posts to see what others are doing. Occasionally I'll try things to see if they'll work, not because some "expert" thought of it. So, I'm at least one counter-example, and I know of numerous intelligent and erudite friends and bloggers who also fit this description. I wonder if you can perhaps provide some examples to support your claim that Java and C# programmers have no depth of understanding?
- abrown28 17y agoOok is a better language than Java.
- Quarrelsome 17y agonow that's just mean.
- mahmud 17y agoIf he said "Oak", instead, I would vote him for being a predecessorist; usually, a bunch of people with better judgment than fadists.
- ilitirit 17y agoLanguage wise C# was than Java from day 1, but the C# toolset and build model are why I prefer C# over Java. I have never had to spend ages trying track down a "class not found" error in C#. Nor have I had to deal with version clashes between libraries. And I might be biased because I develop mainly on Windows, but I think Visual Studio is a better IDE than Netbeans, Eclipse, IntelliJ or JDeveloper.
- kashif 17y agoReally Visual studio is better than Intellij/Eclipse?!? I can tell that you havent done enough programming in the Java world. Have you ever tried any serious refactoring or bothered analyzing your code. I didnt think so, you would have realized why visual studio sucks.. BTW, I program in both C# and Java all the time. Actually, I do about 70% C# and 30% Java. So your claims are crap.
- Caligula 17y agoI would not call all his claims crap. I disagree with his libraries statement but agree that visual studios is better than netbeans or eclipse. I have used c# in vs.net for years up until a year ago and am stuck using eclipse now. I miss vs.net, not so much c#.
- kashif 17y agoHmm...try Intellij Idea and I think you might get over VS. Eclipse is a bit clumsy but really powerful. VS is basically a text editor with intellisense.
- utnick 17y agotry it with resharper. brings it up to java ide level.
- ilitirit 17y ago> BTW, I program in both C# and Java all the time. So do I, so you can drop the holier than thou attitude. In case you didn't know, refactoring plugins for VS do exist, and I use them. But you're just comparing one aspect of the IDE. I use VS Team Suite, so I have built-in Unit Testing, collaboration, modelling (data and code), and multi-language projects in one solution (ie. I can write a COM object in C++ and a C# client in the same solution). IMO, considering your objection, you are the one who hasn't done serious development in any language. (See? It's easy to drop pointless statements like that)
- adharmad 17y agoA thing that I have wondered about: Although Java and C# are similar languages with very similar libraries and features, Java has migrated towards being used for server side and middleware programming. C# however has not gone in this direction even on Windows platforms. What is the reason? Wouldn't it be easy to write the equivalent of Tomcat, JBoss, EJB's etc. in pure C#? It is surprising that some of the apache projects have .NET equivalents (lucene, log4j, ant) but some others dont........
- vetinari 17y agoWindows shops are vary of writing functionality, that might one day compete with Microsoft. Writing net Tomcat/JBoss could clash with IIS and future frameworks. Something like this happened with nant/msbuild and nunit/mstest. Commercial companies find it difficult to justify development of tools with high risk of being obsolete soon (something competing with MS product does not stand a chance in most Windows shops). Apache projects do not care about this risk.
- tumult 17y agoC# is awesome because in a situation where you are using C#, there's a good chance you could use F# instead.
- voidpointer 17y agoSo if the JVM beats CLR but C# beats Java, why isn't there a C# compiler for the JVM? I suspect that all language features of C# should be expressible in Java bytecode, but I have not thought about the details yet. If you know of anything in C# that would be unimplementable in terms of Java bytecode it would be interesting to hear about that.
- rcoder 17y agoJava bytecode is Turing-complete, so there's nothing explicitly preventing you from implementing many of the advanced features of C# atop the JVM. As the OP stated, alternate languages running on the JVM (such as Scala) already do this. The problem is simply that most Java shops use only the officially-blessed Java language. Because Sun has always forced "certified" implementations of the language and platform to conform to their standard, there has been little room for innovation in the source syntax and bytecode format since the release of the first JDK in 1996. In the meantime, programming languages (and the programmers who use them) have moved forward, and Java has failed to keep up.
- icey 17y agoI know it's doable in the other direction (http://www.ikvm.net/ http://www.ikvm.net/). My assumption is that there's no real incentive to create such a beast though. Most people who like C# don't care enough about the JVM to want to deal with that kind of effort.
- leadnose 17y agoMy guess is that C# supports stuff that has no direct and fast implementation on the JVM. IIRC C# has unsigned primitive types, stack allocated objects etc. which JVM doesn't have.
- jwhitlark 17y agoThese days I tend to think of Java as the new assembler; I need to read/understand it, occasionally write it, but I do most of my work in clojure and python, (or scala, whatever your preference)
- solutionyogi 17y ago
- tybris 17y agoThe problem with language features is that people will actually use them. Much better for maintenance to have consistent code. Except for inner-classes, you always know what to expect when opening a Java file. Java's not as elegant as Eiffel or some of the functional languages, but its simplicity has value. (No, I program mostly in C#)
- chaostheory 17y agoNothing new here. I've been working with both for years and I agree. There is one thing that Java still has though, that I somehow doubt C# will have due to culture. Java has way more free or open source libraries. Yes, C# open source has gotten a little better over the years, but it's still not even close (it doesn't help that historically MS has been antagonistic towards open source even within its own products). What does this mean? With C# I have to keep re-inventing a ton of wheels, as opposed to Java where there are already thousands of existing well made ones for me to just grab and use.
- Caligula 17y agoI was a c# dev a year ago and whenever I looked for open source packages to address some requirement, I would always end up at codeproject. It always tended to be poor quality, never updated, etc.. Java has so much more but maybe things have changed over the last year.
- chaostheory 17y agoI doubt the culture will change unless MS shifts its attitude towards open source even more (which is really doubtful). Until then, most people will only release quality stuff on a paid restricted commercial license.
- kashif 17y agoYes C# is an improvement over Java. But, that isnt saying much with the plethora of cutting edge languages available today. I still prefer Java, because C# is limited to the Windows environment,Mono isn't much help yet, and that is a huge limitation for me. Especially because Windows is not conducive to any serious systems programming - its ugly. Another reason in favour of Java is the better open-source eco-system, more libraries and much more mature stuff. C# has had the benefit that all new products/techs have - it leapfrogged.
- deleted 17y ago[deleted]
- geebee 17y agoA good article, but I think the last line is the most revealing... "compared to C# and Scala, it (Java) is almost painful to use..." I think most of the Java community realizes incremental improvements to Java are at the point of severely diminishing returns, and Scala seems to be the next phase (I've heard people jokingly refer to Scala as Java 1.9... of course, this really isn't accurate, but it does capture what's going on in the Java world right now). So in the future, I'm going to be a lot more interested in hearing how Ruby and especally Scala stack up vs C#...
- TweedHeads 17y agoTwo dinosaurs stepping on each others' eggs.
- messel 17y agoThe author has some pretty wide ranging experience. The value I got from the read is that his preferred coding languages are scala and c# for features he describes. Thanks for the share fogus.
- rbanffy 17y agoYou know... C# may be less painful than Java, but, still, it took me 8 years to go through learning C++ after I had learned OOP with Smalltalk and done some programming with Actor (kind of Smalltalk with an ALGOL-ish flavor). I closed my first book on C++ seconds after I saw the overloaded binary shift operator being used to output text. I see my early contact with Smalltalk made me picky and spoiled. Today, it makes not much difference if it's C#, Java or C++, they are all painful well beyond my pain tolerance. It's like smashing one's toes with hammers of different sizes - I am pretty sure even a small hammer is painful enough.
- smakz 17y agoI guess I'll be the lone dissenting opinion and actually favor Java over C#. Java has an extensive library of open source software, which makes it, as they say, more of a platform then a language. From hadoop, to tomcat, to jetty, to hibernate, to spring, to c3p0 (and many, many, many more), you have all the tools you'll ever need to do 95% of the coding work. I definitely get the love around here for dynamically typed languages, but I've never been sufficiently motivated to switch to ruby. The whole philosophy of ruby, "convention over configuration" is applicable to ANY language, including Java. Java's EJB spec was monstrous and XML config file infested, but I've gone through many projects in Java without a single XML config file and following the philosophy of convention over configuration, and it's been great. As to .NET, I would never use it. Never want to get in the business of paying for licenses, not just .NET, but it ties you to Windows server boxes and Windows development boxes.
- rfreytag 17y agoAs regards your last sentence, MS licensing does definitely limit your ability to scale out (over multiple servers, see http://www.codinghorror.com/blog/archives/001279.html http://www.codinghorror.com/blog/archives/001279.html). Mono might just save MS from losing the server mindshare entirely if it can talk itself into letting go of the license more than even the community "promise." I have been pleasantly surprised to find C#/.NET is quite good. Please do force MS' hand by supporting the alternatives. The more good alternatives there are to .NET including improvements to Java, Scala or what have you, the more likely MS will do the smart long-term thing and loosen its licensing restrictions. (please do say why you might disagree - I'm genuinely curious)
- gaius 17y agoThey have completely misunderstood what Markus is trying to do there. He wants a big box so he can do big joins because what he cares about is being able to match people across arbitrary criteria not, at sharding fanboys would do, separating them into separate pools by surname or a hashing function and then you never meet your perfect match because her records are in a different shard to yours... A modern romcom could be written about that.
- 17y ago
- zmimon 17y agoIt's sad, but this isn't really an interesting argument any more these days. Even as a staunch java supporter, I wouldn't try to argue Java is in and of itself as good as C#. I'm more interested in how the 2nd generation JVM languages (Scala, Groovy, etc) compare with C# or the other options on .NET, and on the pros and cons of the whole platform and ecosystem. For my money, no matter how good C# is, I'm not willing to be tied to an environment where the only full, modern implementation is tied to a single platform.
- nathanwdavis 17y agoThis is not new, of course C# is the better language. What is the better environment is up for debate, but the C# language is better designed, friendlier, and more feature-packed leading to more concise code.
- abalashov 17y agoMono notwithstanding, getting into C# culture and ecosystem isn't really feasible for pure-UNIX developers like me. Java takes the cake there.
- danbmil99 17y agowhy not withstand mono? I've worked on two open source projects that used mono and we've had a great time with it. It's portable, FOSS, runs fast, compiles (almost) everything, and has a strong and vibrant community. The JVM is closed source, which is a non-starter for me. Why should I invest in a proprietary platform that is lagging in features and support? MS won this battle, get over it
- ekiru 17y agoThe JVM is GPLed.
- danbmil99 17y ago"The JVM is robust, mature, fast, and (above all) portable." mono is damn portable.
- eli 17y agoI dunno. What's it do that my turning machine with infinitely long tape doesn't do?
- known 17y agoPerl have http://perldoc.perl.org/perldsc.html http://perldoc.perl.org/perldsc.html * arrays of arrays * hashes of arrays * arrays of hashes * hashes of hashes * more elaborate constructs