[om-list] C# vs. Java

Tom and other Packers TomP at Burgoyne.Com
Wed Nov 21 09:45:58 EST 2001


Mark

    So, why use C# instead of C/C++?

tomp

----- Original Message -----
From: "Mark Butler" <butlerm at middle.net>
To: "One Model List" <om-list at onemodel.org>
Sent: Tuesday, November 20, 2001 10:28 AM
Subject: [om-list] C# vs. Java


Here is an interesting comparison of C# and Java:

  http://www.prism.gatech.edu/~gte855q/CsharpVsJava.html

The languages are similar on a superficial level, but have several critical
differences.  Coming from a C++ background, C# is a language I would like to
program in, and Java is not (although I have to anyways).  Some of the major
reasons follow:

1. Operator overloading in C# allows one to write types with value
semantics, as opposed to Java, where a string or a complex number isn't
equal to another "object" with the same value.  This is the opposite of the
way we think in real life.  The *only* thing important about a complex
number is its value - not where it is stored on memory or any other perverse
notion of identity.  Two different instances of the same value should be
treated as semantically identical, as in natural languages.

2. C# implements types that can be allocated on the stack or in large arrays
without heap allocations for each element. A heap allocation is generally
three orders of magnitude slower than stack based allocation. In short,
unless you have heap allocation and garbage collection in hardware, this
weakness makes it impossible to develop high performance systems in Java.
That is why fast Java GUI is an oxymoron. No amount of just in time
compilation can remove this heap allocation overhead in Java - your only
option is to stick to primitive (i.e. non-object) types.  C# has a very
clean solution for this problem.

3. C# has a notion of properties, which have all the encapsulation
advantages of getter/setter methods in Java, without forcing you to write
all your code using exceeding ugly GetXXX()/SetXXX() method calls.

4. C# does not force you to split every public class into its own file, let
alone force you to build an umpteen level directory structure to make a
reasonable program.

5. C# implements a reasonable subset of #ifdef/#else/#endif functionality
for build configuration. This is *extremely* useful.

6. Other very helpful C# features missing in Java: parameter passing by
reference, enums.

7. C# is based around an architecture designed to allow cooperative
development in a wide variety of languages, where Sun's support for Java is
the more typical Microsoft style my way or the highway...

In short, as long as we have compatible implementations on open systems
(e.g. the Mono project), I believe that C# will become the most significant
development to come out of Microsoft in a decade, one that is likely to bury
Java on the merits and force Sun to develop a Java++ with similar
capabilities. Visual Basic and COM will be blips in comparison.

 - Mark

_______________________________________________
om-list mailing list
om-list at onemodel.org
http://www.pairlist.net/mailman/listinfo/om-list






More information about the om-list mailing list