Viewpoints-Microsoft Proposes a New Language C# (pronounced 'See Sharp')28 Jun 2000
On June 26 ‘00, Microsoft announced that it had submitted a new language called C# (pronounced ‘C Sharp’) to the Geneva-based standards committee “ECMA” (http://www.ecma.ch/).
C# is intended to be packaged with the next version of Visual Studio (version 7) which will now be called Visual Studio.NET. According to Microsoft, C and VC++ provide the programmer with tremendous amount of fine-grained control and flexibility over their code while sacrificing ease of development. Visual Basic, raises productivity and sacrifices flexibility by omitting a mechanism for low-level code control. VB neither interoperated with pre-existing systems, nor did it always mesh well with current Web programming practices.
Visual J++ occupies that middle-ground between Visual C++ and Visual Basic, offering both fine-grained control over low-level OS features, programming flexibility, and improving productivity multi-fold. It is the BEST environment to program in COM (Microsoft’s Component Object Model). The lawsuit with Sun has changed a lot of things. Microsoft seems to be contemplating on deprecating Visual J++!!
C# from Microsoft may be a replacement for Visual J++ and an attempt to replace the void which will be left by its non-inclusion in VS.NET. According to Microsoft, C# would provide programmers with rapid development, combined with the power to access all the functionality of the underlying platform without sacrificing the power and control that have been the hallmark of C and C++. It will provide an environment that is completely in sync with emerging Web standards and one that provides easy integration with existing COM applications. Additionally, it would allow the ability to code at a low level if and when the need arises.
In my opinion, C# will do extremely well within the Windows camp. Microsoft makes excellent tools for developers. C# will be integrated into Visual Studio.NET so it’s IDE will be top-notch. However, on other platforms, C# may just be another programming language. While C# is indeed being handed over for standardization, what is being standardized is nothing more than the core programming language. The true meat, the new Visual Studio COM libraries, are not described in the C# language specification. The COM library that ships with Visual Studio 7.0 is what is going to have all the punch in it. With this library you will be able to kick out killer Windows apps in VC++, C# and VB by using something called the “Common Language Subset” (CLS) interface. C# is a thin language core that sits somewhere between Visual C++ and Visual Basic. Visual J++ now has the spot but it is safe to assume that it is, in Java terms, being deprecated.
There are some things about C# that sound neat:
- Automatic garbage collection
- Everything is an object (including the primitives! which means I can code 10.toString () !!!).
- Multi-dimensional array support (the [,] notation)
- Support for operator overloading
- structs are held and passed by value on the stack. These have the same properties as classes, except that they are accessed by value rather than by reference.
- C# allows XML data to be mapped directly into a struct data type, rather than a class, for greater efficiency.
- Supports conditional compilation
- true and false are both keyword and boolean literal
- a foreach statement
- “delegates” are a language feature.
- Will be better than VB
- With C#, every object is automatically a COM object
- C# supports methods with variable number of parameters.
- interfaces are part of the C# language. Interfaces are defined in C# as having methods and properties, and generating events; but there is a new twist in that C# interfaces can derive from more than one interface, which is not possible with MIDL. The actual interface implementation is in classes or structs which can implement one or more interfaces.
Heated Good/Bad Debates Surround these features:
- It uses a preprocessor
- The preprocessor has no support for macros
- Compiles to platform native executable (without second step)
- Doesn’t compile to platform independent “.class”-like file
- Lots of attempts to remove ‘unnecessary’ brackets. Dangling else is solved by using the nearest corresponding if.
- There is no distinction between caught and uncaught exceptions
- switch statements follow the “no-fall-through” mechanism.
- switch statements can also be applied to strings (case-sensitive)
- Properties are supported, i.e., what looks like a variable assignment or access in client code can have get and set methods associated with it.
- The addition of all of the unsigned types doesn’t look like a win, but when you discover that the only implicit conversions are those which preserve information, it looks okay.
- You can turn on or off overflow checking for arithmetic operations in a code block. Not sure if this propagates to the methods that are called within that code block
- Inside a specially marked code block, developers are allowed to use pointers and traditional C/C++ features such as manually managed memory and pointer arithmetic (these blocks are qualified by the keyword unsafe)
Some folks feel these things are sad:
- Far less dynamic than Java. (i.e. no dynamic class loading)
- Has C++ style namespaces
- break and continue can’t have a label.
- Event handlers are less general than anonymous classes and aren’t cleanly integrated.
- no covariant return types
- Provides large primitive data types and overflow checking constructs, but does not appear to convert to unbounded representations.
- The name resolution rules look too involved, although there are some interesting features with respect to interfaces.
- Methods are not virtual by default.
- C# doesn’t seem to have built in security
- No template-like mechanism available
- Looks very similar to Java.
- The entry point into an application is the static Main() function of a class, and your code interacts with the operating system through instances of a standard class library.
- You can write your own classes, which supports single inheritance from other classes, but can be derived from several interfaces.
- The language supports value types (such as int and double) and reference types (e.g. instances of classes, arrays and strings). Just as with Java, C# reference types are ‘managed’ - in other words, the memory they consume is maintained by a garbage collector.
- It also allows you to define ‘indexers’, which are essentially like the C++ operator , and it has C++-like destructors.
- All COM interfaces have to indicate the direction of data transfer and the meaning of all pointers that are passed. C# uses the parameter modifiers ref and out to indicate if a parameter is passed by reference, or is an ‘out’ parameter. However, since pointers do not exist in C# code, interface definitions are not concerned with them.
- C# has been designed with the ability to change the language through ‘attributes’.
Far back in December 1997, Mary Kirtland wrote an article in the Microsoft Systems Journal (MSJ) called “The COM+ Programming Model Makes it Easy to Write Components in Any Language”. It makes me wonder if C# was what she was referring to then. Whatever be the case, I for one, and hordes of Java/COM developers like me, will miss Visual J++ for a long time to come…