A place to keep my thoughts on programming

October 6, 2008 geek , , ,

C# 3.0 language features vs. Java’s OS community

I’ve been in a constant struggle for a number of years and it’s a battle between wanting to program in C# but envying the variety of open source projects available on the JVM.

And this isn’t so much a windows/linux thing, because mono vs. native .NET is really the least of my problems. The mono team has done an amazing job letting me write code without worry in Visual Studio and deploy on linux. With mono 2.0 just out, i have no code left that doesn’t just work when i copy the dll’s over. The fact that i do a lot of .NET on linux is not a pain point for me.

But when it comes to open source libraries, the eco-system on java is just so much richer. Think of an API or protocol and google it for java and you’ll find it. Do the same for .NET and your chances are much smaller. And if you find it, chances are it’s a port of Jfoo to Nfoo. So you could say, I’ve got library envy.

So why not just go java? Well, there are a number of C# language features that many might accuse of being “sugar”, but i find them incredibly useful to express my intent in code. Here are the things that keep me in C# 3.0:

  • Delegates, especially anonymous delegates. For concurrent programming, they are essential
  • Events. Sure, they are just more sugar on top of delegates, but for async, having the ability to easily declare, subscribe and fire events are a god sent.
  • Properties. Public fields can’t be part of an interface and if you ever need to attach observation to the value change, then fields are a dead end. And seriously, getFoo()/setFoo() is busy work for the compiler. It’s less readable and more error prone.
  • Lambda expressions. Yes, i want a taste of functional with my imperative
  • LINQ. And i don’t mean LINQ to SQL. This isn’t about databases, this is dealing with collections, doing map, reduce, filter and projection. Yeah, you can loop by hand, but it’s so much less expressive or readable.
  • var. Type inference is the way to go for static type languages. Less clutter, still strongly typed. You can get most of the benefits of dynamic languages with type inference and not have to give up type safety. I hope that we get closer to duck typing tho.
  • Dead easy interop with native processes. No, my VM is not some abstract world that shan’t know about its environment. It’s just a better way to code, so let me do machine specific things without making me pay penance in blood for it.
  • A language with much more innovation. Ugh, I know MS made innovation a dirty word in their anti-trust battles, but it’s really true for C#. C#2.0’s best features were aped by Java 5 and C#3.0 is once again miles ahead in new capabilities. People might argue whether that’s a good thing, but it can’t be disputed that C# is innovating much more rapidly.

So there you go, I’m a C# fan boy. I admit it. But still, i got this library envy. What’s a guy to do? I see two possible paths, C# on the JVM or java libs on mono. Both are mostly possible, but I really need to do some spikes to know where the pain starts with the two options.

C# on the JVM: Mainsoft Grasshopper

Author in C#, cross-compile IL into java byte code. Mainsoft is apparently collaborating with the mono guys, so generally what makes it into mono in terms of language features will make it into Grasshopper. Need to take some of my projects and see what happens when i try this.

Java on C#: IKVM

Compile java code into .NET IL using IKVM. This is dependent on the state and compatibility of IKVM and Java. Need to take some popular java open source projects and see what happens when i try to build them using IKVM.

Either sounds like inviting a life of debugging edge cases that no one else cares about. But I don’t see a better option. Am I overlooking some other path? Should i stop whining and just go java? Is the OS situation not nearly as bad on .NET as i make it out to be and I can just continue as is? Things that keep me up at night.

1 to “C# 3.0 language features vs. Java’s OS community”

  1. Zarfishan says...

    There is a another alternative service "CodePorting C#2Java Converter" available. It is a web-based application that converts your .net app, projects and files to java in the cloud which means you don't have to download it just upload your .Net code and it will be converted to java instantly.

Leave a comment