

Switching from C# to Java - amitshah
http://lpeer.blogspot.com/2010/04/switching-from-c-to-java.html

======
rit
Totally reactionary, prejudiced statement.

But my first reaction on headline before reading the article was "Ugh. I'm
sorry". (I will read it in a second, I felt this obdurate urge to rant BEFORE
I read it).

I coded in Java for work (After being hired to do Java) for years, then went
over to Python, and worked with some C# for about a year. Now I'm back working
with Java, and Scala (for which I have lots of love - it has a lot of what I
love about Python but in many cases better).

There are little things in C# that just really give it an edge over Java.
Among other things relating to Generics (Which are awful to begin with in that
the JVM currently erases type information at compile time [Scala has a few
clever hacks to get around it]) - as I understand it, C#/CLR automatically
generates multiple specialized paths for all possible primitive types with
generic collections.

And being a fan of closures, anonymous functions, etc. Java is just painful.
C# has these, and more.

Now Off to read the article :)

~~~
brazzy
I keep seeing people bash Java's Generics because of type erasure - but what
exactly is so awful about it? All the questions on stackoverflow where the
answer is "impossible because of type erasure, or use this workaround" don't
seem to be about terribly important or useful things.

~~~
thejake
The case that I've bumped up against several times is when trying to get the
class of the generic object. Something like:

    
    
      T obj;
      obj = getObjFromSomewhere();
      log(T.class);
    

This type of operation is most useful if writing framework type of some sort.
I've come across it when trying to write a generic JPA base DAO type of class.

~~~
rit
Scala has Manifests to emulate reified types for just this reason.

[http://www.scala-blogs.org/2008/10/manifests-reified-
types.h...](http://www.scala-blogs.org/2008/10/manifests-reified-types.html)

It's improved a bit in 2.8 - in porting some code I discovered a nice little
hack that lets you declare your variance like this:

[A <: SomeBaseClass <: Manifest]

Which tells the compiler in an oh so gentle manner to reify for you.

------
bruceboughton
I can understand porting C# code to Java code, but what I don't understand and
what the article doesn't explain is how they handled their dependencies, i.e.
System.* libraries.

They clearly didn't port the CLR libraries to the JVM, so they must have
modified their code to work with Java libraries, e.g. Swing, etc. To me, it
seems like this would be the bulk of the work, not language translation from
Java to C#.

~~~
ivenkys
Good point - its not the language translation per-se but the ecosystem
surrounding it unless there's is one of those projects where they hand-coded
everything and used no external libraries at all. I doubt it very much though.

------
Tichy
How does the converted code look, though? Is it viable to continue working on
that, rather than fixing the original C# code? (Ie comments would be carried
over in the conversion).

~~~
AndrewDucker
That would be my question. In my experience code that's been transformed
programmatically is not meant for the eyes of mortal man.

------
tzs
It sounds like they rejected Grasshopper, the .NET to Java converter that
works at the bytecode level, without doing a test to see if it would have
worked, on the grounds that they wanted to be open source.

They probably should have given it a try, because if it had worked, it would
have opened up a possibility that they seem to have completely overlooked. Use
Grasshopper to convert at the bytecode level, then use a Java decompiler to go
from bytecode to Java source.

You'd lose comments in the source code that way, but I bet it would not be
hard to write a tool to transfer the function level comments from the C#
source to the Java source. Subsequent hand editing to translate any C#-isms to
Java-isms in the comments, and restore any crucial sub-function level
comments, would probably have only taken a few days.

------
CWuestefeld
As with many HN articles, the headline is misleading. Really, the language
switch is a symptom, and not the driver of the decision.

From the article, their requirements included:

 _one of the first tasks we got was to make the management application cross
platform, well this was expected considering the fact that the acquisition was
done by RedHat._

And:

 _Sticking with C# requires technologies to help us run it on Linux. We found
Mono ..., and the second option we found was Grasshopper which is a project of
Mainsoft to compile MSIL to Java Bytecode. ... These 2 solutions were taken
off the table ... we wanted to use a technology supported by Red Hat._

So it appears to me that the decision had nothing at all to do with technical
strengths of the language. Moreover, it had nothing to do with the platform as
such -- whether its technical strengths or any end-user demographics -- but
purely politics driven by Red Hat.

~~~
rwmj
No, they tried Mono and found it wasn't ready for primetime. Read the article.

------
plesn
I wonder why they couldn't use Mono. I can't really grok how they managed
library usage, and how difficult it will be to maintain the java one when on
platform updates etc.

