Log in

C# now a better language than Java

C now a better language than JavaJava VM is a professional platform. It’s mature, it’s fast, it’s highly portable, and there are loads of languages running on it.

Worse, though, for Java enthusiasts: Java has fallen behind C#. I’m boning up on C# using O’Reilly’s C# in a Nutshell book. (See http://oreilly.com/catalog/9780596001810/. As an aside, the “Nutshell” books are an excellent way to learn a new language, if you already know n other languages.) I’m only partway through the book, but it’s already clear to me that, overall, C# (the language) now has more goodness in it than Java does.

Here are some things C# now has that Java does not:

  • Lambdas, which are way better than anonymous inner classes. (C# has anonymous inner classes, too.)
  • Delegates: You can kind of do this in Java, but it’s not as clean as in C#
  • Operator overloading:This feature can be abused all to hell, but it is still occasionally useful, especially in libraries and in DSLs.
  • Properties: No need to write getters and setters. Everything looks like a direct field access, even if it isn’t. This is Python’s idiom, and Scala’s, too, and once you start using it, you never want to expose explicit getters and setters, ever again. foo.x += 1 is so much more readable than foo.setX(foo.getX() + 1).
  • A yield coroutine capability: Though I prefer Python’s syntax (and Scala’s) to C#’s, this is a powerful and highly useful capability. If you’ve ever used it to build lazy iterators (in Python, Scala, C#, whatever), you know what I mean.
  • Extension methods: These are the C# equivalent of the Scala implicit type conversion feature, and they’re damned useful. They permit you to “extend” existing classes, even if they’re final, without actually extending them. Like the Scala version, there’s a mechanism for bringing the implicit conversions in scope; they don’t happen automatically. (Think of them as a kind of scope-controlled monkeypatching.)
  • A null coalescing operator that provides a simple syntax for dereferencing a reference and supplying a default if the reference is null.

In addition, C# has many of the same features as Java, including:

  • interfaces
  • generics
  • autoboxing and auto-unboxing
  • annotations (though C# calls them “attributes”)

Though JVM is robust, mature, fast, and (above all) portable. But Java, the language, has fallen behind, and it now lacks a lot of the useful features C# has. One of the reasons I’m all over Scala these days is that it corrects those flaws in Java, providing many up-to-date features while still permitting me to use the power and convenience of the JVM. Either via libraries or built-ins, Scala provides the same features as C#, with a few more thrown in for good measure. (I also happen to think Scala is a better language than C#, but I’ll save that tangent for another time.) But, in the .NET world, C#, not Scala, is the lingua franca. And C#, and .NET, are the biggest hearts-and-minds competitor Java has.

Sun and the Java community have allowed Java, the language, to stagnate to the point where, compared to C# and Scala.


Tagged under Programming

Tech News

China is worried an AI arms race…

Experts and politicians in China are worried that a rush to integrate artificial intelligence into...

Most Read

A Mothers Love

A little boy came up to his mother in the kitchen one evening while she...


Get Bitcoins and other Cryptocurrency With Ease…

It is a new Revolutionary Concept on how to make Bitcoins, Litecoins, Ethereums, Dogecoins, Dashcoins...