Open Source .NET Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source .NET Development [Electronic resources] - نسخه متنی

Brian Nantz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Standardization


Microsoft worked hard to push the CLI and C# through standardization, and they did so with record results. I cannot think of a programming language or platform that made it from the Version 1 release to an international standard faster than C# and the Common Language Infrastructure (CLI). This is all due to Microsoft playing their cards correctly and not for aught.

Standards Organizations


Microsoft originally submitted the CLI and the C# programming language to the European Computer Manufacturers Association (ECMA) for standardization. In December of 2002, the second edition of ECMA-335 Common Language Infrastructure (CLI) became a standard. The C# programming language became ECMA-334 simultaneously. Because of the close relationship of ECMA with the International Standards Organization (ISO), C# and the CLI finished their fast-track standardization in April of 2003. The CLI is now ISO 23271:2003, and C# has become ISO 23270:2003. So when working with the CLI and C#, you can be assured you are working with a real standard from a real standards body and not some unheard of organization. Microsoft's ISO standardization is an all-around win, especially in large organizations (such as governments) that may require the use of ISO programming languages. I do not believe that Microsoft would want to suffer the international humiliation of retracting a standard, even if ISO would allow them to. ISO standardization allows for other implementations of the CLI and C# standards to be created and used with great confidence and freedom. But this then begs the question, "What exactly is in the standards?"

What Is in the Standards


Now that I am getting technical, it is time to start defining and using the technical terms associated with the standards. Figure 2-1 shows the different parts of the standards and how they interact.

Figure 2-1. The CLI Standard.

[View full size image]

All of the acronyms used in Figure 2-1 are definitely confusing. The CLI is the Common Language Infrastructure already discussed. To make things a bit more confusing, Microsoft called their implementation of the CLI a Common Language Runtime (CLR), which we will look at as one of the implementations later in the chapter. The CLI is meant to be a platform-independent virtual execution engine. Nothing in the standard would require a specific operating system or platform, but it intends to abstract your C# code from what lies beneath. The CLI uses a Common Intermediate Language (CIL) that is CPU-independent. CIL is an output from a compiler that is a step above native CPU-specific code. The CIL is typically fed to a just-in-time (JIT) compiler for transformation into native code. Perhaps the most critical component of the CLI is the garbage collector (GC) because if the garbage collector is not efficient, the whole platform will not perform and must be discarded. Up to this point, the CLI sounds similar to a Java Virtual Machine (JVM). In fact, the CLI is similar to a JVM in allowing the "code-once-run-anywhere" dream that turned into the "code-once-test-everywhere" nightmare. But the best is yet to come. The Common Type System (CTS) sets the stage for the Common Language Specification (CLS).

NOTE

The Base Class Libraries (BCL) are not a part of the CLI standard. However, I included them in the graphics for this chapter to point out one of the biggest benefits of the CLI. This benefit is a collection of base classes that can be used from any language. This is great news for many languages like VB where you really could not do true threading, exception handling, and other critical functionality.

The CTS requires that all Types derive from the System.Object base Type and are broken down into two basic categories: Value Types and Reference Types. Figure 2-2 demonstrates the CTS Type Classification System.

Figure 2-2. Type Classification.

Table 1.1 in Chapter 1 lists just a few languages that support the CLS and are freely available for Open Source, but there are numerous other CLS languages available that are not listed in this table. CLS takes programming language integration a step further. Existing technology such as CORBA or COM allowed language interoperation to a point, but the CLS allows all languages access to the CLI base framework, easy language interoperation, and cross-language inheritance. Miguel de Icaza from Ximian's Mono project put it best:

We [Ximian] were interested in the CLR because it solves problems that we face every day. The Java VM did not solve this problem.

The .NET Framework: Using the

ECMA

Standards: An interview with Miguel de Icaza,

MSDN

My interest in .NET comes from the attempts that we have made before in the GNOME project to achieve some of the things .NET does:


  • APIs that are exposed to multiple languages

  • Cross-Language Integration

  • Contract/Interfaced-based programming…


Peeking under the Lid of Open Source .NET

CLI

Implementations, DevX

This language agnostic approach truly sets the CLI apart from any other programming platform and provides a very rich set of APIs to all languages.

C# is the language of choice when using the CLI because it is a standard and shows off most (but not all) of the CLI functionality. For a good book on just the syntax and semantics of the C# language, see

A Programmer's Introduction to C# (Second Edition) by Eric Gunnerson, Apress

I like Eric's book because he sticks to what the C# language can do without sidetracking into other parts of the .NET framework. When I want to know if a particular feature, such as defaulting optional function parameters, is supported by C#, I do not want a book that covers everything from ASP.NET in C# to XML in C#. While those parts of the framework are essential to understand, they are also broad and apply to all CLS-compliant languages.

http://www.hutteman.com/weblog/2003/04/06-56l), illustrates this perfectly as he observes on his blog, and I quote:

It's interesting how C# and Java seem to be playing leapfrog. C# started out with many of Java's features and some useful improvements of its own, and now Java is taking a number of C# features like attributes, enums, foreach and autoboxing, and adds some more like generics, static imports, and extendable enums.

Enums are something that are long overdue for Java, and their implementation in JDK 1.5 seems extremely powerful… .NET 2.0 will also add support for generics. From what I heard, they will leapfrog Java again on that one by allowing that type-information to be available at run-time as well. I seem to remember reading somewhere that Java's generics will be compile-time only. At run-time, a Collection<String> in Java will look like any other Collection…

Hopefully, in the near future, a language will support exceptions to my liking in a more robust way. In my opinion, no language does a good job of simplifying exception handling, but Java probably comes a little closer to this than other languages. A tool called CLRxLint (http://www.software4net.com/products/clrxlintl) from software4net does provide Java-like checked exceptions for CLS-compliant languages, but it's still not an ideal solution. This awkward support for exceptions is why so many people punt and just catch the base Exception class and get themselves into trouble. It would be nice to be able to use reflection to find out what exceptions you should expect to be thrown. For more insight on this issue, see the interview (http://www.artima.com/intv/handcuffsPl) with Anders Hejlsberg (the leader of the C# design team), Bruce Eckel, and Bill Venners, where Anders discusses his reasoning for not using checked exceptions.

What Is Not in the Standards


If you peek ahead at Figure 2-3, you will see how Microsoft's implementation of the CLI is a lot more than just what they have chosen to standardize. Now that we know what is in the standards, we should look at what is not in the standards. Some of the most innovative parts of Microsoft's CLR (including ADO.NET, ASP.NET & Windows Forms) are not part of the CLI or C# standard. Windows Forms are a great advancement in rapid development and ease of use over traditional MFC User Interface programming. I personally believe that Windows Forms and User Interfaces in general are probably the most difficult things to make platform-independent. Keeping a consistent look and feel is not adequately accomplished in Java's Swing, TCL/TK, GTK+, or any other toolkit I have seen. After just playing with a UI for a few seconds, I can tell what was used to create the UI. Although users do not explicitly understand the differences, it has been my experience that users subconsciously know when a UI does not quite fit with the paradigm of the operating system they prefer. ADO.NET is another non-standard that, once you have used it, is hard to live without. ADO.NET mixes XML and data access very well, making n-tier systems much easier to implement. Unfortunately, the non-standardization of ADO.NET truly hinders pure Web service development because datasets cannot be passed between .NET Web services and other Platforms (like Java's) Web service implementations. It is this author's opinion that Microsoft would benefit from standardizing ADO.NET because then it could be used more frequently to exchange data between programming platforms. ASP.NET is also a fairly large innovation that is not standardized. ASP.NET introduces the unique idea of using server-side controls, which gives the programmer a closer programming model to a thick client. This makes for faster Web UI coding and, with the help of vendor components, a richer UI for the client.

Figure 2-3. Microsoft's Common Language Runtime.

[View full size image]

In addition to things that are not in the standard, there are a few things in the standard that are not very clearly defined. Platform Invoke (P/Invoke) is definitely a good example of that. Microsoft knew that .NET is not going to be able to replace all the existing functionality that other languages have. In addition, most users are going to want to use legacy code from .NET. To allow for this, Microsoft created P/Invoke. P/Invoke allows you to make calls into existing libraries or the system to gain additional functionality that .NET could not implement, such as serial port communication. The big question of course is, "How exactly is this supposed to work on other operating systems like Linux or Macintosh?"


    / 275