> Well yes, its not like you cannot emulate properties, events,
> delegates, operator overloading of C# in the Java language. All Im
> saying is that these are first class features of C# and make the
> language more expressive. If u do emulate them in Java, u loose the
> syntactic conveinece that u have in C#. For example the C# feature of
> operator loading becomes verbose and looses its elegance.
But your statement was they they couldn't be exppessed in bytecode. If they
can be emulated in Java, then obviously they can be expressed in bytecode.
> And some of the emulated features might also add to performance
> problems due to excessive method calls or other housekeeping
> operations. Then the more complex things such as unsafe code blocks in
> C# dont have a direct syntactic expression in Java.
This is true; .NET plays nicer with non-.NET code than Java does with
non-Java code.
> And yes, some of the convention changes u mentioned r not compatible
> with Java. The other conventions that break with Java are things like
> absence of the concept of checked exceptions,
This makes .NET *less* expressive than Java; it's as if all Java methods
were declared "throws Throwable".
> absence of the concept of
> non-static nested classes,
Again, less expressive
> C# 2.0's anonymous method ( may roughly be
> similar to Java's anonymous classes), etc...
[quoted text clipped - 7 lines]
> expriences to work with modern features than Java does. Hence
> conversion from C# do Java is not a prefereable thing to do.
C++ had more features still; it's not always a good thing.
Ranganath Kini - 30 Dec 2005 07:08 GMT
About my first reply, I apologize, perhaps I shud have rephrased it
more clearly. My intention was to say that one "could" emulate features
of C# in Java but u "cannot do full justice" to those emulated
features. In sense that you cannot use them in Java with the same
flexibility as u can in C#.
>This makes .NET *less* expressive than Java; it's as if all Java methods
> were declared "throws Throwable".
My intention here is not to compare or decide which is a superior
platform. I want to highlight the difference between .NET and Java in
the context of source code translation from the former to the latter. I
want to say that if u need to translate from C# to Java, u need special
treatment to exceptions. Certain checked exceptions of Java correspond
to unchecked exceptions of .NET, so u need special care when u
translate from C# to Java and ensure that the Java code uses proper
try...catch...blocks to handle checked exceptions. The same with
non-static nested classes.
And no doubt C++ has many features. But where C# and Java compile to
intermediate code, C++ code is popularly( here im not considering
managed extentions to C++) compiled to native code. Also C# and Java
resemble a lot in terms of features than C++ . So I can keep C++ out of
the scope of this discussion.
Mike Schilling - 30 Dec 2005 16:40 GMT
> My intention here is not to compare or decide which is a superior
> platform. I want to highlight the difference between .NET and Java in
[quoted text clipped - 5 lines]
> try...catch...blocks to handle checked exceptions. The same with
> non-static nested classes.
You'ce picked two of the easiest things to "emulate". All C# exceptions are
unchecked, so any translated Java methods should "throw Throwable". And all
nested classes should become static.
Ranganath Kini - 30 Dec 2005 17:55 GMT
It isnt as easy as having all translated method to "throws Throwable".
No doubt u cud do that, but wats the idea then of having specialized
exceptions to trap special error conditions. For example, the
System.IO.IOException is an unchecked exception but the
java.io.IOException is a checked exception.
I write a C# program that works with files and has method that may
possibly throw an System.IO.IOException. When I translate this program
into Java, I cannot simply translate the method and have it marked as
"throws Throwable", if I do so, after translation, I again need to go
thru the translated Java code and change "throws Throwable" to "throws
IOException" so that I can handle IOException properly and also adhere
to Java's notion of handling checked exceptions.
This is one of the reasons why I say that a translation from C# to Java
is not a elegant one.
Mike Schilling - 30 Dec 2005 18:24 GMT
> It isnt as easy as having all translated method to "throws Throwable".
> No doubt u cud do that, but wats the idea then of having specialized
> exceptions to trap special error conditions. For example, the
> System.IO.IOException is an unchecked exception but the
> java.io.IOException is a checked exception.
Because C# doesn't declare what exceptions are thrown by a method, all C#
exceptions are unchecked. This is precisely like a Java method that
declares "throws Throwable", not that it does throw every possible
exception, but that it might. You need to do some reading about what
"checked exception" means.