C# – A Hype Or Reality?

 

C#, (pronounced "C sharp") is a newprogramming language announced by Microsoft in June, and scheduled todebut at the Microsoft Professional Develper�s Conference(PDC). C# isMicrosoft researcher Anders Hejlsberg's latest accomplishment. C# looksastonishingly like Java; it includes language features like singleinheritance, interfaces, nearly identical syntax, and compilation to anintermediate format. But C# distinguishes itself from Java withlanguage design features borrowed from Delphi, direct integration withCOM (Component Object Model), and its key role in Microsoft's .NetWindows networking framework.

In this article, I will examine commonmotivations for creating a new computer language, and speculate onwhich might have led to C#. Next I will introduce C# with regard to itssimilarities to Java, c, c++. Then I will discuss a couple ofhigh-level, fundamental differences in scope between Java and C#. Iclose the article by evaluating the wisdom (or lack thereof) indeveloping large applications in multiple languages, a key strategy for.Net and C#. Currently, C# and .Net are available only as a C# languagespecification (not yet in final form), a "d Preview" for Windows 2000,and a quickly growing corpus of articles on MSDN.

Microsoft says that the c# language definitionhas been primarily derived from C and C++, and many elements of thelanguage reflect that. C# is broader than Java in what its designerschose to inherit from C++ (such as structs), and it also adds newfeatures of its own (such as source code versioning). But it's toopremature to write off Java. C# is yet to evolve into a language thatis adopted and taken up by the developers' community. But the hype thatMicrosoft is creating around its new language is worth taking note of.But the response at the moment is: "It is a riposte to Java."

C# is more like Java than anything else, inspite of Microsoft's silence on the subject. This is to be expected, Isuppose, given the recent success of the latter and the gains inproductivity over C++ that have been reported by the companies that useit.

The kind of impact and the acceptance levelsthat Java has been able to build is clearly evident by the number ofprogrammers (estimates say 2.5 million developers are using Javaworldwide) working on this language and platform. The number ofapplications that have emerged through this language is mind-bogglingand has penetrated to every level of computing, including wireless andmobile phones (remember the launch of Java phones in Japan). Can C#create this level of acceptance among the user community?. We have towait and watch as rightly pointed out by Kalpathi S. Suresh, chairmanand CEO of SSI Ltd, "I find all these incremental. If C# isn't there,we could always get (back) to Java or C and C++. These are not exactlynew technologies; they are more of marketing hype created by bigcompanies. We'll have to give them time to settle and see if these willreally have any impact on the IT industry."

C# Features Derived From Java

Classes: Classes in C# are declaredvery much as they are in Java. This makes sense because experience hastaught us that the Java model works very well. The Java keyword importhas been replaced by using, which performs the same basic function. Thepoint at which a class begins execution is the static method Main().The following Hello World program demonstrates the basic form:

using System;
class Hello {
static void Main() {
Console.WriteLine("Hello, world");
}
}

In this example, the name System refers to anamespace that contains a set of basic C# utility classes. Thenamespace contains the Console class, which is used in this example tooutput a string.
� Classes can be abstract and final: A class that is declared asabstract cannot be instantiated; it can only be used as a base class.The C# keyword lock is like the Java keyword final, which declares aclass to be non-abstract, but it also cannot be used as the base ofanother class.
� Interfaces: Just as in Java, an interface is an abstract definitionof a collection of methods. When class or struct implements aninterface, it must implement all of the methods defined in theinterface. A single class can implement a number of interfaces. Theremay be some subtle differences that surface later, but this featureappears to be unchanged from the one in Java.
� Boolean operations: Conditional expressions result in the bool datatype, which is a distinct type in the language. There is no directconversion between bool and any other data type. The Boolean constantstrue and false are keywords in the language.
� Errors: As in Java, throwing and catching exception objects manage error handling.
� Memory management: There is automatic garbage collection, which is provided by the underlying .NET framework.

C# Features Derived From C and C++

� Compilation: Programs compile directly intothe standard binary executable form. If the previous Hello Worldprogram were to be stored in a text file named Hello.cs, it could becompiled into an executable named Hello.exe.
� Structs: A C# struct is like a C++ struct in that it can contain bothdata declarations and methods. However, unlike C++, structs aredistinct from classes and do not support inheritance. However, likeJava, a struct can implement interfaces.
� Preprocessor: There are preprocessor directives for conditionalcompilation, warnings, errors, and line control. The preprocessingdirectives available are:

#define
#undef
#if
#elif
#else
#endif
#warning
#error
#line []

There is no #include directive. There is noassigning of values to symbols on the #define statement, so there is nosource code substitution–the symbols are only for use on the #if and#elif directives. The number (and optional name) on the #line directivemodifies the line number and source file name reported by #warning and#error.
� Operator overloading: Some operators can be overloaded, and somecannot. In particular, none of the assignment operators can beoverloaded. The overloadable unary operators are:
+ – ! ~ ++ — true false
And the overloadable binary operators are:
+ – * / % & | ^ << >> == != > < >= <=

Features Unique to C#

C#'s most intriguing facets are itsdifferences from Java, not its similarities. This section (and much ofPart 2 of this series) covers features of C# that Java implementsdifferently or entirely lacks.
� Intermediate language : Microsoft is very flexible about choosingwhen MSIL is compiled to the native machine code. The company takescare to say that MSIL is not interpreted, but compiled to machine code.It also understands that many — if not most — programmers accept theidea that Java programs are inherently slower than anything written inC. The implication is that MSIL-based programs (written in C#, VisualBasic, "Managed C++" — a version of C++ that conforms to the CLS –and so on) will outperform "interpreted" Java byte code. Of course,this has yet to be demonstrated, since C# and other MSIL-producingcompilers have not yet been released. But the ubiquity of JIT compilersfor Java make Java and C# relatively equal in terms of performance.Statements like, "C# is compiled and Java is interpreted," are simplymarketing spin. Java byte code and MS
IL are both intermediateassembly-like languages that are compiled to machine code forexecution, at runtime or otherwise.
� Declarations in the namespace: When you create a program, you createone or more classes within a namespace. In this same namespace (outsideof a class) it is also possible to declare interfaces, enums, andstructs. The using keyword must be employed to address the contents ofother namespaces.
� The fundamental data types: There are a wider variety of data typesthan found in C, C++, or Java. The types are bool, byte, ubyte, short,ushort, int, uint, long, ulong, float, double, and decimal. Like Java,all of the types are of a fixed size. Like C and C++, there are bothsigned and unsigned versions of each. Like Java, a char contains a16-bit Unicode character. New with C# is the decimal data type, formonetary data, that can contain up to 28 significant base 10 digits.
� The two fundamental classes: A class named object is the base classof all other classes. A class named string is as much a part of thelanguage as object. Being a part of the language makes is possible forthe compiler to use it–whenever you code a quoted string in yourprogram, the compiler creates a string object to hold it.
� Argument passing: Methods can be declared to accept a variable numberof arguments. The default is to pass fundamental data types by value.The ref keyword can be used to force an argument to be passed byreference, which allows the argument to accept a return value. The outkeyword also causes a pass by reference, except no initial value isexpected.
� COM integration: The biggest win for Windows programmers with C# maybe its painless integration of COM, Microsoft's Win32 componenttechnology. In fact, it will eventually be possible to write COMclients and servers in any .Net language. Classes written in C# cansubclass an existing COM component; the resulting class can be used asa COM component too, and can then be subclassed in, for example,JScript, to provide yet a third COM component. The result is anenvironment in which components are network services, subclassable inany .Net language.
� Indexer: An indexer is similar to a property except that, instead ofa property name, an indexing value inside square brackets (like anarray subscript) is used to anonymously address a member of a class.

public class ListBox: Control {
private string[] items;
public string this[int index] {
get {
return items[index];
}
set {
items[index] = value;
Repaint();
}
}
}

The iterator can be used to anonymously address members of the internal arrays of strings like this:

ListBox listBox = …;
listBox[0] = "hello";
Console.WriteLine(listBox[0]);

� Delegates and callbacks: A delegate objectcontains information required to call a specific method of a specificobject. Think of it as a smart method pointer. The delegate can bepassed to another location, and accessed to make a type-safe call tothe represented method. A callback method is an example of a delegate.The event keyword is used in the declaration of methods that are to bethe delegates called when an event occurs.

Conclusion

The similarity between C++ and C# is a greatbenefit to any organization with an existing training investment in Cand C++. Programmers accustomed to C++ will have no troubleunderstanding C#. Moreover, Windows programmers who invested timelearning Java (often in the form of Visual J++) will come up to speedon C# even more quickly than C++ programmers. The common the theme inthe programming world is "If you learned Java, and you know C++, you'vebasically got 90% of what you need for C#."
I hope this has given you a feel for where C# stands in relation toJava and C++. Overall, I believe C# provides greater expressiveness andis more suited to writing performance-critical code than Java, whilesharing Java's elegance and simplicity, which makes both much moreappealing than C++.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="468" height="60"><param name="movie" value="/banners/Ad2.swf?clickTAG=http://www.red-gate.com/products/ants_profiler/index.htm?utm_source=chelp%26utm_medium=banner%26utm_content=vsmenu%26utm_campaign=antsprofiler" /><param name="quality" value="high" /> <embed src="http://www.csharphelp.com/banners/Ad2.swf?clickTAG=http://www.red-gate.com/products/ants_profiler/index.htm?utm_source=chelp%26utm_medium=banner%26utm_content=vsmenu%26utm_campaign=antsprofiler" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="468" height="60"></embed> </object>

Most Commented Articles :

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!