Languages Built on the .NET Framework

At the time of this writing there are about 20 programming languages—existing or under development from Microsoft and third parties—that can be used for building .NET applications. If that is not exciting enough, all these languages will be able to work together more seamlessly than ever before. This integration is possible because all these languages are compliant with the Common Language Specifications (CLS) and they all run under the same runtime. We will look at some of these languages here, namely C#, Visual Basic .NET, Jscript .NET, C++, and a few others.

The runtime is the core enabler of multilanguage program development and execution in .NET. The runtime manages the execution of code and provides services that make development easier. .NET compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed-execution environment.

Code that needs to execute under the runtime environment is referred to as "managed code." The runtime provides the following benefits to managed code:

  • Cross-language integration The runtime makes it easy to write components and applications that interact across languages. For example, you can define a class in C# that extends another class that was written in Visual Basic .NET.
  • Security The runtime provides an automatic built-in security mechanism for determining whether a particular managed component or application is allowed to run and that degree of trusted access that should be given to protected resources.
  • Versioning and deployment support The runtime uses metadata stored with managed code to ensure that your component or application has the specified versions of everything it needs.
  • Debugging and profiling services The runtime provides built-in services and tools to help developers debug and profile managed code easily.
  • Memory Management The runtime provides memory-management features that manage object lifetimes automatically.

C#

With .NET, Microsoft introduced a new programming language called C# (pronounced "c sharp"). C# is a modern object-oriented language and is designed from the ground up to work well within the .NET Framework. It provides seamless support for developing systems that rely on .NET, from managed components to XML Web services. Microsoft touts C# as a new language that combines the power of C++ with the ease of use of Visual Basic. Just as C++ and Visual Basic have been the de facto standards for developing applications for Windows, Microsoft hopes that C# will become the preferred language for developing .NET applications.

C# is consistently object-oriented. Everything in C# is an object, including primitive types like integer, floats, and the like. In addition, in line with a stricter object-oriented approach, C# ditches the concept of global functions, types, and variables. C# provides the equivalent static methods and variables to make code easier to read and less prone to naming conflicts. In addition, program execution no long starts from a global main function but instead starts with a call to a static Main( ) method in a class.

Many error-prone constructs and idioms in C++ are removed from C#. For example, C# does not support multiple inheritance and preprocessor macros, and instead uses interfaces and namespaces as a more elegant solution. C# also dispenses with the irksome -> pointer indicator and the :: namespace operator of C++. In C# everything is represented by a dot.

Data types have been significantly simplified in C#. For example, all character data is encoded as Unicode. A char is a char is a char. Gone are the confusing unsigned char, signed char, and wchar_t typed data types used in C++. A 64-bit integer is a long, not an __int64, and a 32-bit integer is simply int.

C# does retain some of the more powerful features of C++. For example, C# supports operator overloading, enumerations, and a variable number of method arguments. You can even use dangerous constructs like pointers, structs, and static arrays in C#, but they need to be used within explicitly declared unsafe classes and methods.

C# has great potential for becoming the tool of choice for .NET programming with its unique combination of power and simplicity. If you want to learn more about C#, check out the C# tutorials and references in the .NET Framework SDK documentation.

Visual Basic .NET

The price that you sometimes have to pay for running under the runtime is that specific languages might need to adapt to conform to it. Nowhere is this more evident than in Visual Basic .NET. Microsoft has introduced so many fundamental changes to its earlier Visual Basic that you should consider this a brand new language. As a result, upgrading previous versions of Visual Basic projects to Visual Basic .NET will typically require more preparation than a simple port.

Most of the new features in Visual Basic .NET stem from it having to comply with the CLS and accommodate the runtime and its associated programming model. Visual Basic .NET has many new object-oriented design features and much higher levels of type safety than previous versions of Visual Basic. The new object-oriented capabilities in Visual Basic .NET include support for full inheritance, parameterized constructors, method and properties overriding, method and operator overloading, and shared members.

Visual Basic .NET was also enhanced with modern programming constructs such as structured exception handling and threading. Some of the more significant features replaced or retired in the move from Visual Basic 6 to Visual Basic .NET are:

  • Default methods and properties are no longer supported.
  • Many keywords, including Let, Gosub, VarPtr, ObjPtr, and StrPtr, were retired.
  • Visual Basic .NET introduces new syntax for factors like class properties, declaring and initializing variables, and especially arrays.
  • Parentheses are now required for all methods, even those without arguments.
  • All arguments are now ByVal by default.
  • And, Or, and Xor are strictly for boolean operations. The new BitAnd, BitOr, and BitXor should be used for bitwise arithmetic.

Again, these are just some of the changes introduced in Visual Basic .NET. You should read the .NET Framework SDK documentation for a complete coverage of programming in Visual Basic .NET.

Jscript .NET

Together with C# and Visual Basic .NET, Microsoft introduced a new version of JScript called Jscript .NET. Jscript .NET combines the existing features of JScript with features usually found only in class-based and compiled languages. It is a true object-oriented language with full support for industrial-strength features such as inheritance and interfaces. And because JSript is a fully-fledged .NET-compliant language, you can create classes in Jscript .NET which can be used by other .NET languages and, conversely, extend classes defined in other languages.

Jscript .NET introduces many performance-improvement features. The most important of these, undoubtedly, is that Jscript .NET is a true compiled language, making its run-time performance comparable to C# and Visual Basic .NET. From a language perspective, Jscript .NET now provides strongly typed programming support through the explicit type declarations. Typeless and implicit typing programming is still supported through a new type-inferencing technology so existing scripts will still run.

Unlike Visual Basic .NET, Jscript .NET was specifically designed for full backward compatiblity, so all your existing code will continue to work just fine. All the new features, such as typing and class declarations, are optional. The new features, however, will allow you to reap the benefits of improved performance and robustness.

For more information about Jscript .NET, check out the JScript .NET section in the .NET Framework SDK documentation.

C++

C++ is alive and well in the .NET Framework. You can continue to use Visual C++ in .NET in the same old way, but to be able to take full advantage of the benefits of the runtime, Microsoft has extended C++ to provide support for "managed programming." These Managed Extensions for C++, as they are called, are mainly comprised of a set of new keywords and attributes. With Managed Extensions for C++, the runtime will provide automatic object lifetime and memory management (including garbage collection), enhanced exception handling, security, and finally debugging and profiling services for your C++ components and applications.

If you are a C++ programmer and you are interested in exploring managed programming, you should read the "Programming with Managed Extensions for C++" chapter in the .NET Framework SDK documentation.

Other Languages

As we mentioned earlier, besides C#, C++, and Visual Basic .NET, many other languages provided by third-party vendors can be used for .NET programming. For example, ActiveState Corp. (http://www.activestate.com) provides .NET implementations of the Perl and Python programming languages. Interactive Software Engineering is working with Microsoft to develop an implementation of the Eiffel programming language for .NET. Other vendors are also working on providing more programming languages, such as Pascal and even Java, for .NET. For the latest developments in this area you should visit the Microsoft MSDN Third Party .NET Resources Web site at http://msdn.microsoft.com/net/thirdparty/.



XML Programming
XML Programming Bible
ISBN: 0764538292
EAN: 2147483647
Year: 2002
Pages: 134

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net