|
|
|
|
This article begins a new series for OCI: "The OCI .NET News Brief". It's being created to help OCI and its friends stay in touch about about .NET, C# and related technologies and issues.
.NET is a Microsoft trademark that potentially refers to any new version of any product marketed by Microsoft. But what these newsletters are about is a more specific interpretation of the term ".NET". We will be discussing the parts of .NET that apply to software development, including C# (C Sharp) and other languages, the ECMA and ISO standardization processes, the CLI (Common Language Infrastructure), the .NET Framework, and Visual Studio .NET.
C# is a relatively new programming language designed primarily by Anders Hejlsberg at Microsoft starting in 1998, publicly announced in July 2000, and released in January 2002, with two public beta tests and a few release candidates in between. C# has roots in C, C++, COM, XML, VB, Delphi, Java, and other technologies. C# is probably more like Java than any other language, however, it adds some features, removes a few, and is different in terms of its philosophy. C# brings back some useful C++ features that were omitted in Java and standardizes some concepts that had been proprietary Microsoft extensions of other languages. Finally, C# brings in some features that are not in any of the languages that we have mentioned.
C# is a compiled language. That means that what is installed on end user computers is not the source code, but instead is a lower level and more efficient representation of the source code. Like classic Pascal and Java, but unlike C, C++ and later versions of Pascal, the "compiled" (translated) representation of your program source code is not encoded in a language that your computer hardware understands, but instead is coded in an "intermediate" language (IL). That means that an extra piece of software is required (the Common Language Runtime [CLR]) to actually run a .NET program. It also means that it could be possible in the future (though it will depend on decisions made by computer manufacturers) to run a .NET program without change on a machine architecture or operating system that was not envisioned when the program was written. And it means that there is an extra level of architectural and processing complexity in the overall system that a lower-level language such as C does not have. All of these concepts will be very familiar to experienced Java developers.
The .NET Framework is the runtime environment for programs written in C# and other .NET languages. If you are familiar with Visual Basic (VB), it's analogous to (though larger and quite different from) the VB runtime. It's even more similar to the Java Runtime Environment (JRE), though there are important differences here too. The .NET Framework, like the JRE or the VB runtime, has to be installed on a computer before a C# or other .NET program will run. The framework is available for free download and redistribution from Microsoft and can be installed on Windows 98, ME, NT 4, 2000 and XP. The next version of Windows is expected to have the framework pre-installed.
The .NET Framework consists of the Common Language Runtime (CLR) and the Framework Class Library (FCL). The CLR is what actually starts and controls a .NET program on behalf of the underlying operating system, and provides application, memory and thread management; object activation; code verification; security; "just-in-time" compilation to machine code, and other runtime services. The CLR can be thought of as providing a "Virtual Machine" in which .NET programs execute (though they do not run in an interpreted mode). The FCL is a large class library for use by the CLR and all other .NET software. The FCL is written mostly in C#.
The .NET Framework is a superset of the Common Language Infrastructure (CLI). The CLI is the standardized part of the .NET Framework (see below for more on this) and does not contain any Windows-specific functionality, though a few of its abstractions are modeled on relevant parts of the Windows architecture.
In December 2000, an ECMA committee was formed to produce a standard for C# and a subset of the .NET Framework (the Common Language Infrastructure -- CLI). Two standards, one for the C# language and another for the runtime, were adopted in December, 2001 and are being submitted to ISO for further standardization. Members of the ECMA standards committee included Alcatel, Compaq, HP, IBM, Microsoft, Netscape, Sun, and other companies. The ECMA standards encompass the entire C# language and a subset of the .NET Framework called the Common Language Infrastructure (CLI). These standards are available for free download and are not copyright nor trade secret, and do not require licensing. Anyone may implement C# and the CLI on any hardware and operating system without entering into a license agreement. The C# standard is designated as ECMA-334 and the CLI standard as ECMA-335. Each is about 500 printed pages and is available for free download as a PDF. Both are very detailed and are intended to facilitate interoperable implementations among diverse platforms.
Microsoft and Corel have produced "shared source" implementations of C# and the CLI for Windows and FreeBSD. The source code to these implementations is available for download at no charge for learning, teaching and modification. Access to the code is covered by a license agreement, but there are no licensing fees for non-commercial use. It is also expected to be possible to license the code as a starting point for commercial C# and CLI implementations, but this will probably not be free.
At this time, there are two independent open source projects to implement C# and the .NET Framework, known as Mono and DotGNU Portable.NET respectively. These are both open source projects, though the licensing terms and scopes differ. Both are currently targeted to Linux. Neither has reached the beta test stage at this time, but both are very interesting and worth following. The potential that both offer is the ability to develop and run .NET software on Linux and other UNIX and UNIX-like platforms. In the event that many commercial and retail .NET applications become available (and this seems likely, since Microsoft appears to be "betting" much of its future on .NET) then at least in theory some of them will be useable on Linux. It has also been stated that still others are working on .NET implementations, but those names are not publicly known at this time. If it turns out that many .NET-targeted applications are released into the commercial and retail markets, we might expect to start hearing announcements from platform vendors of .NET support, either via licensing from Microsoft or by reverse-engineering.
If you have read this far, you may already have a good idea of what the CLI is. It's essentially the standardized part of the .NET Framework, including a file format for executables and libraries, the Common Intermediate Language (IL), and a Base Class Library (BCL). The Base Class Library consists of around 300 "types" -- classes, interfaces, enumerations, and structures and is intended as a "standard library" similar in scale to the C library. (These types are also found in the .NET Framework, but are a small subset of it.) Of course, in 2002 the idea of a standard library is not what it was 15 or so years ago. The CLI has classes for collections, diagnostics, globalization, input/output, networking, reflection, runtime support, security, text handling, threading, XML, and sockets. It does not contain any GUI classes. By way of comparison, the .NET Framework, a superset of the CLI, is composed of well over 3000 types.
The Common Intermediate Language (CIL or IL) has been mentioned already several times. It is the language of the .NET "virtual machine" - a computing machine, or processor, which may not exist in physical form. It's analogous to Java bytecode and can be thought of as an Object Oriented machine language. All .NET language compilers produce IL. All .NET runtime implementations consume IL. As with other machine languages, there is a verbose, source code form of IL and a compact, binary form. The .NET Framework SDK come with some tools that support the direct use of IL. Ilasm.exe is an IL "assembler" (equivalent to a compiler in the case of a higher level language). Ildasm.exe is an IL disassembler. Below is a tiny example of some IL source code produced by using Ildasm on a compiled C# program (this shows one function, public static void Main( ) ):
.method public hidebysig static void Main() cil managed
{
.entrypoint
// Code size 11 (0xb)
.maxstack 1
IL_0000: ldstr "Hi"
IL_0005: call void [mscorlib]System.Console::WriteLine(string)
IL_000a: ret
} // end of method Test::Main
Since C# like Java in many ways, the quickest way to describe C#, assuming the reader knows Java, is to list some similarities to and differences from Java. It is hoped that non-Java developers will also benefit from this comparison. Unfortunately, the scope of this article does not allow a complete description of C#, nor even a thorough comparison to Java.
virtual keyword: Methods in Java are polymorphically overridable by
default. In C# a method must be declared virtual in order to override it.
structs: An old keyword borrowed from C and C++, but used with a new
twist. In C#, a struct is a value type. Value types are allocated on
the stack when defined within a method, and on the heap, but inline, when defined
within a class. Structs are very efficient in terms of memory allocation overhead
and storage size: they occupy only the sum of their members' sizes plus alignment
overhead.
void f(System.Object)
is defined, it is legal to call it with a literal integer parameter,
MyClass.f(123) for example. To unbox a boxed value, the boxed value is
cast back to the value type.
getValue() and
setValue(mytype myvalue) in Java, properties allow variable-like access
via methods.
enum keyword: C# provides true enumerations as part of the language,
with a bonus never provided by C and C++ in that the name of each value is preserved
at runtime as a string. Also, the exact integer type of each enumeration can be
specified. Enumerations provide type safety without the overhead of a reference type.
foreach keyword: provides concise iteration over collections
switch on string
readonly modifier: differs from a constant in that if an imported
readonly member changes, the change will be picked up
unsafe keyword: allows pointer manipulation for performance-critical
code. Unsafe code is not "verified".
using keyword: There are two forms of the using keyword.
First, in a role similar to the Java import keyword. Second, and more interestingly,
it provides something semantically similar to try ... finally for the purpose of
ensuring that the Dispose( ) method is called (on a type that implements the
IDisposable interface).
Microsoft is not new to Object Oriented (OO) development, having supplied C++ and COM tools and infrastructure since the early 1990s, and Java since 1996. However, .NET is the first fully OO framework to be made available by Microsoft for all of their programming languages, and represents a major new emphasis on Object Oriented development. Visual Basic developers had access to a powerful Component Oriented architecture (COM), but did not have good support for more traditional OO development. This is no longer the case. To some extent, .NET places existing VB developers at a relative disadvantage, and provides a running start to experienced OO developers. Prior experience in any OO language and methodology is going to be an asset to anyone considering .NET. The balance of general OO experience and knowledge versus Microsoft-specific language and environment experience is going to be an important factor in staffing and training decisions.
The .NET Framework SDK is freely downloadable from Microsoft's web site. It includes four command-line compilers (C#, VB.NET, C++ and JScript), numerous other command-line tools, the framework itself, and a large documentation library. The redistributable part of the framework (the part needed to run, but not develop, .NET programs) is available for separate download. These kits are licensed but there is no charge for them, nor is there a charge to redistribute the runtime. Between the SDK documentation and tools, and what's available on the web, one can easily spend hundreds of hours. Clearly, your main investment is going to be time.
As recently as six months ago, there were only handful of books on .NET (and these were limited to preliminary specifications), but now there are many. This writer recommends books from Microsoft Press, O'Reilly, Apress, and DevelopMentor. Books can help you come up to speed more quickly than just studying the online documentation.
To come up even more quickly, consider some training courses. If you are an experienced developer, but have not been using an Object Oriented language, consider some general OO training before focusing specifically on .NET.
Finally, if programming .NET is going to be a regular activity for you, consider purchasing Visual Studio .NET, some other Integrated Development Environment (IDE), or a language - and tool - aware editor. IDEs can make programming faster and more enjoyable, though their initial ease of use will hide important details that developers need to master whether they use an IDE or not.
We have briefly discussed some definitions, standardization, and the history and status of C#, the .NET Framework, and the CLI. As a free standard not owned by Microsoft, C# and CLI have some interesting possibilities ahead of them. And the shared source implementation may provide a jump start to educators and students. We have not talked at all about features of the .NET Framework that are a superset of the CLI, including GUI development with Windows Forms, graphics programming with GDI+, web application programming with ASP.NET, web services, unification with XML Schema, database access with ADO.NET, and COM interoperability. We plan to discuss these and other topics in future articles. Your comments and questions will help us decide what to write about! We look forward to hearing from you.
Object Computing, Inc (OCI) has been providing educational services to clients, industries and universities since 1993. We offer one of the most comprehensive distributed Object Oriented training curricula in the country. These curricula focus on the fundamentals of OO technology; with close to 40 workshops in OOAD, Java, XML, C++/CORBA and Unix/Linux.
For further information regarding OCI's Educational Services programs, please visit our Educational Services section on the web or contact us at training.
|
|