December 01, 2000
C# Strikes a Chord
C# Strikes a Chord
C# Strikes a Chord
Syntax Comparison
Table 1 summarizes the comparison between C++, Java and C#. We have deliberately
put C# in the middle column flanked by C++ and Java to make it easier to see
in what direction C# leans with regard to each feature. The Executable Environment
and Language APIs are also included in the comparison. These are as important
as the language's syntax in determining how the programming language gets used.
In fact, this has always been true with languages. The choices between interpreted
versus common .obj files and linking options have determined the flexibility
and critical runtime performance of a number of languages. In addition, the
availability of a common set of subroutine libraries and system APIs have been
a selling point for languages from Fortran to C to Smalltalk and now Java and
C#.
The first thing you note is that similarities between C++, Java and C# go well
beyond HelloWorld. The number of common or synonymous keywords, operators
and flow of control statements never drops below 75 percent. And why not? Pascal
derived much syntax from Algol, and of course C++ from C. That programming language
designers are following Isaac Newton's suggestion and deriving their syntax
from a common starting base is no small boon to programmers. Already pressed
with unremitting change in hardware and software technology, anything that helps
to keep a language familiar and easily learned is welcome.
There may seem to be some anomalies among the 75-percent-common syntax features.
Even though C# has only 52 operators, because C++ has about a dozen keyword
equivalents to character operators (such as bitand == "&" and bitor
== "|") it has a number of duplicate operators matching C# equivalents.
The result is that 59 C++ operators map into some (but not all) of the 52 C#
operators. Note also we have called these "common or synonymous". Thus we consider
C#'s is operator to be substantially synonymous with Java's instanceof.
Perhaps the best approach is to highlight the notable differences in syntax
between the two languages.
|
Table
1
Comparison of C++ and Java to C#
|
| |
Syntax
Features |
C++
|
C# |
Java |
| |
Program
code to intermediate code |
No |
Yes |
Yes |
| |
Single
inheritance, all objects implicitly derived from master class, Object |
No |
Yes |
Yes |
| |
Unicode
for char, String, identifiers |
No |
Yes |
Yes |
| |
Uniform
implementation of primitive type bitsizes |
No |
Yes |
Yes |
| |
All primitive
types derived from Object |
No |
Yes |
No |
| |
Allows
pointers, explicit memory mgmt. |
Yes |
Yes |
Simple,
=null |
| |
Struct,
enum |
Yes |
Yes |
No |
| |
Common
or synonymous keywords to C# |
56
of 74 |
69
of 69 |
46
of 50 |
| |
Flow of
control statements |
9 |
9 |
7* |
| |
Common
or synonymous operators to C# |
59
of 70 |
52
of 52 |
47
of 56 |
| |
Explicit
exception handling with throw, try-finally-catch |
Yes,
no finally |
Yes |
Yes |
| |
Operator
overloading |
Yes |
Yes
except for = |
No |
| |
Preprocessor
statements (#define etc) |
Yes |
Yes |
No |
| |
In-processing
attributes |
No |
Yes |
No |
| |
Parameter
options in, out, ref, params |
No |
Yes |
No |
| |
Compiler
aids/hints asm, inline, register |
Yes |
No |
No |
| |
Templates,
generic programming |
Yes |
No |
No |
| |
Executable Environment |
| |
Open, cross-platform
intermediate language code |
No |
Promised |
Yes |
| |
Garbage
collection and memory management |
No |
Yes |
Yes |
| |
Type safe
assignments, method invocation, initializations, array bounds checks |
Some |
Yes |
Yes |
| |
Explicit
invocation sequence for applets, servlets, beans/components |
No |
No |
Yes |
| |
Fine-grained
security of access/operation |
No |
Yes |
Yes |
| |
Disassembly
and metadata sharing |
Some |
Yes |
Yes |
| |
JIT-Just
In Time compilation and performance enhancers |
No |
Yes |
Yes |
| | Language
API |
| |
Number
of standard classes and methods |
100's |
100's |
1000's |
| |
Open source
API |
Some |
To
be decided |
All |
| |
Standard
container, math, I/O classes, etc |
Yes |
Yes |
Yes |
| |
Direct
tie to XML for documentation |
No |
Yes |
Yes |
| |
Direct
use of XML for interface and remote procedure calls |
No |
Yes |
No |
* 7 are identical: no foreach, goto
Next: Notable Differences
1 | 2 | 3 | 4 | 5 | 6
Previous Page |
1
|
2
|
3
|
4
|
5
|
6
Next Page