Chapter 2: Common Type System


A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they comprise.
Benjamin C. Pierce, Types and Programming Languages

Ultimately, all programs are built from data types. At the core of every language are built-in data types, ways of combining them to form new types, and ways of naming the new types so they can be used like the built-in types.
— Jim Miller, The Common Language Infrastructure Annotated Standard

Overview

The Common Language Runtime (CLR) — or more precisely any implementation of the Common Language Infrastructure (CLI) specification — executes code inside the bounds of a well-defined type system, called the Common Type System (CTS). The CTS is part of the CLI, standardized through the ECMA and International Organization for Standardization (ISO) international standards bodies, with representatives from industry and academia. It defines a set of structures and services that programs targeting the CLR may use, including a rich type system for building abstractions out of built-in and custom abstract data-types. In other words, the CTS constitutes the interface between managed programs and the runtime itself.

In addition to being the interface, the CTS introduces a set of rules and axioms that define verifiable type safety. The process of verification categorizes code as either type-safe or -unsafe, the former categorization of which will guarantee safe execution within the engine. Type-safe execution avoids a set of memory corruption risks, which executing unverifiable programs could lead to. The runtime permits execution of such programs, however, leading to great power and flexibility at the risk of encountering corruption and unexpected failures.

This unified type system governs all access, manipulation, and combination of data in memory. It enables static detection and resolution of certain classes of programming errors, a structured way in which to build and reuse abstractions, assistance to compiler authors through a safe and abstract virtual execution system (VES), and a self-description mechanism for programs using rich metadata. Type safety and metadata are two primary platform features that have provided the largest productivity, security, and reliability benefits the platform has to offer. Other factors include runtime services, such as Garbage Collection, and the wealth of APIs that the Framework offers. Each of these will be discussed extensively in future chapters.

Thinking in terms of "pure CTS" is often difficult. Nearly all programmers work with a concrete language, such as C#, VB, C++/CLI, or Python, when writing managed libraries and applications. Languages provide their own unique view of the runtime system, either abstracting away, hiding, or sometimes even exaggerating certain parts in different ways. But they all compile down to the same fundamental set of constructs. This diversity is one reason why the CLR is such a great programming environment and can readily support an array of unique languages. With that said, it can also be a source of challenges when attempting to understand and/or bridge two languages' unique view over the same underlying type system. This chapter should help to clarify this.




Professional. NET Framework 2.0
Professional .NET Framework 2.0 (Programmer to Programmer)
ISBN: 0764571354
EAN: 2147483647
Year: N/A
Pages: 116
Authors: Joe Duffy

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