Stan Lippman: 'C ++CLI Panorama Experience' Opening Way

xiaoxiao2021-03-06  43

I have visited China's Shanghai and Beijing, and I participated in Microsoft held in both.

TECH-ED

The technical conference, where I am very honored to introduce us to you.

C / CLI

Work. Everyone's feedback is very good, especially the Chinese young generation programmer

C / CLI

The love and understanding left a deep impression. There, I also met a developer from Shanghai and a technical author.

Li Jianzhong

Mr. After discussion, we decided to cooperate and write a series.

C / CLI

Articles, and exclusively authorize the Chinese "Programmer" magazine in the form of "C / CLI Panorama Experience" column. This essay is to briefly introduce some of the background we write this column - a taste of "Fixed Field" in a movie.

In the face of C / CLI, many people's first problem is naturally "What is C / CLI", I personally like to be seen as a bridge between static programming and dynamic programming. The name of C / CLi itself contains a set of terms - and the most important terminology is the least obvious.

First, look at the first term "C ", which certainly refers to the C programming language invented by Bjarne Stroustrup during the Bell Lab. It supports a static object model that is highly optimized for code execution speed and actuator space. In addition to the heap memory allocation, it does not support any changes to the application at runtime. It allows us to communicate infinitely to the underlying machine, but for the active type in the running program, and its accessibility is very limited, or it is impossible. It is a very successful programming language, but it cannot adapt to the current web programming environment and related security issues - this has become an increasingly important consideration in the current programming.

Look at the third term "CLI", the general language infrastructure, which is a multi-layer architecture that supports dynamic component programming models. In many ways, the object model and C are completely opposite. In the CLI, there is a runtime software layer (ie, the virtual execution environment) runs between the application and the underlying operating system, the application code to the underlying machine will be quite strictly restricted; in fact, the CLI is not allowed at all. The code in the environment makes such access. On the other hand, the CLI allows us to fully access the activity types in the running program, and the relevant program infrastructure, and even allow us to dynamically construct additional types and program infrastructure. These flexibility is of course accompanied by a considerable space (space occupancy space) and time (program execution efficiency), but it solves the growing problems and needs in the connection-based computing environment.

Finally, then look at the second term, that is, the intermediate slash "/", it tends to ignore people. It represents a binding of C and CLI, which is the focus of C / CLI design. According to this, an answer to "What is C / CLI" is "it is a binding of static C object model and dynamic CLI component model".

For C / CLI, a C programmer only needs to add it to her [Mr.] The existing programming toolbox can be. To become a C / CLI programmer, you don't need to give up anything else, although you have to enter a new technology world, you still need to learn it - I hope you can enjoy this process, at least I know I am Such. From this view, we can also think of C / CLI as a gate to another world. C / CLI integrates dynamic, component-based programming models, and ISO-C , which is very similar to our integration of generic programming and C of the Template in the Bell Laboratory. In both cases, your code investment and coding experience will be reserved. This is a basic requirement for our design C / CLI.

General Language Foundation Construction (CLI) is a multi-layer architecture that provides a wide range of services for all CLI languages. For example, a general-purpose type system (CTS) is defined in the CLI, and each CLI language provides a mapping of CTS. This type of system is organized as a complete class inheritance system by a root base class. In fact, each CLI type is a class - not only a numeric type like Integer, Double, but also a literal constant. Each CLI type (or value) represents an Object (all CLI types), such as values ​​3.14159, such as string often "Homer Simpson".

Single base class provides support mechanisms for runtime type query and code generation (commonly referred to as reflection) [Translation Imposion 2], which is lack of ISO-C . We will discuss the dynamic programming characteristics of the CLI in a series of articles in the future.

In addition, the CLI also supports a configuration called property metadata, which allows us to define some feature classes, and then associate it in the CLI type and currently running program - this is effective The type and program structure built in the CLI are extended. These user-defined features can also be obtained by reflecting mechanisms, and the application can determine the conditional logic according to their values. This is also part of the dynamic component programming of C / CLI as C . Again again, type reflection and characteristics will be discussed in our column.

So, how do you learn C / CLI for everyone? One of the key points to learn C / CLI is to learn the generalized type system (CTS) of the underlying, which includes the following three types:

1. Polymorphic reference type, which is used for all kinds of inheritance. We will discuss them in some columns in the early columns.

2. Non-polymorphic value types are used to implement some types of high efficiency requirements such as numerical types. We discuss it after the reference type.

3. Abstract interface types are used to define a set of operations for reference types or value types. The interface provides a different type of design mode for more inheritance. We will also have a series of column articles to discuss them.

Map CTS is mapped to a set of language built-in types for all CLI languages, although the syntax used in various languages ​​varies. This is also the first design level to face in a CLI language. For example, in C #, we can define an abstract base type Shape with the following code (some specific geometric objects will inherit from it).

Public Abstract Class Shape {...}

In C / CLI, we define the same type with the following code. Public Ref class shape abstract {...};

In addition to grammatical differences, the actual representation of the two statements is exactly the same. Similarly, in C #, we can define a specific class POINT2D with the following code.

Public struct Point2d {...}

In C / CLI, we define the same type with the following code.

Public value class point2d {...};

Our selection of grammar is based on the following starting point: Tight the CLI type and the ISO-C type together with an intuitive design perspective.

Therefore, it is simply that a language is not correct than the bottom layer CLI in another language. Instead, each CLI language is just a view of its own CLI object model.

The second point to learn C / CLI is to learn the underlying CLI elements we choose directly to the programmer. For example, CLI provides garbage collection services for all languages. A language cannot choose whether to support garbage collection, but only how to better provide this service.

In the CLI, all objects of a reference type can only be assigned on the CLI hosted stack. This means that C / CLI supports two dynamic stacks - local stacks (without any form of automatic memory recovery mechanism), and CLI hosted stacks. For these two dynamic stacks, developers typically use some form of NEW operators to assign objects; if the operation is successful, the address of the initial position in the stack will be returned. But both are different because the location of the object in the CLI hosted stack is likely to be re-adjusted in the garbage collector and the subsequent compression. If the location of an object is re-adjusted, one of the services included in the CLI runtime will transparently update all referring to this object.

This makes us face a difficult choice: we call these referrals as a pointer, and continue to express them with the syntax of the pointer? Or introduce a new similar syntax to indicate that they need special processing? We finally decided to adopt the latter and see the following code:

N * pn = new n;

R ^ rn = gcnew r;

Here, N represents a local type, and R represents a CLI reference type, and the hat-shaped symbol (^) represents the related address is a trace handle on a hosted stack - that is, any re-re-object location Adjustment will be traced by the CLI, and the corresponding handle will be transparently updated. The keyword GCNew is used here as a New expression that deals with the CLI hosted pile.

Value types can also be on the hosted stack, although this is not necessary. This happens when they are a reference type of members. If we allow the address of a reference type internal member to be obtained, the local pointer is not suitable because the positions of these members need to be tracked. One solution is to simply ban the function. This language will certainly become more simple, but both the language will become more weak -, for example, we will not be able to traverse the CLI array through the address value of the elements, because the CLI array is a reference type, the elements within it Located on the hosted stack. Does not provide such functions means that the CLI array will not be available to Iterator mode and generic algorithm in the standard template library (STL). This is unacceptable for a C programmer.

Support Get The address of the value type that may be located in the hosted stack also needs to introduce a tracking pointer, which is called the Tracking Interior Pointer. In addition, we also support the concept of tracking reference - it has an alias semantic similar to local reference, but it will be transparently updated by the CLI when necessary. Finally, we also support the concept of a Pinning Pointer, which prevents the garbage collector from moving the objects to be referenced within the scope of the pointer. These new symbols and complex indirect types thereof are produced after we have repeatedly learned and understand the hosted stack. In the face of short-lived hosted reactors, we need some kind of way to understand and use them, we believe that these additional indirect types can give you a lot of help. We will discuss them in detail in the future column articles.

We show a layer of mapping on the underlying CLI implementation model to the second design level selected for a CLI language. What kind of mapping options depends on what kind of programs and programmer models are positioned in the programming language. When you choose a CLI language to program, you are actually choosing a programmer model. Our positioning of C / CLI programmers is those system programmers who have experienced deeper. These programmers usually provide basic constructors and critical applications for high-level commercial logic. At this time she must It is necessary to consider the scalability and performance of the system at the same time, so there must be a system-level perspective on the underlying CLI.

The third point of learning C / CLI is to learn the features directly provided by non-CLI itself. This is also a design choice to face to each door-oriented language, and an embodiment of mutual distinguishing between various CLI languages.

For example, the CLI itself does not support multiple types of inheritance (MCI), but only supports multi-interface inheritance and single-class inheritance. However, the Eiffel language has chosen multiple types of inheritance that supports the source code level when designing the CLI implementation. This requires a smart, even complex design to map the source code level inheritance to the single-class inheritance model of the underlying CLI. The Eiffel language designer thinks that this map is a positive element for the Eiffel programmers on the CLI platform.

On the third design level of this C / CLI, we did not use multiple types of inheritance programs. One reason is that we can't convince any simple or elegant places that have a multi-interface inheritance model. We don't have enough experience to determine which solution is absolutely excellent, but my intuition tells me that multiple inheritance (MCI) is a dead end. Our main concern at this design level is to provide some additional solutions for those where the CLI itself is lacking, and we are mainly concentrated in the following three aspects:

1. An automated solution is provided for some CLI to provide an automated solution, such as a Deterministic Finalization, and a rare resource release.

2. Provide some special class member functions, such as copy constructors and copy assignments, and the operator supported by the CLI, provide some extended support for some operators, for example, to support function objects (Function Object) The Call Operator () "of the design mode.

3. Providing a static parameterization mechanism to support a standard template library (STL) for the CLI type, because the generic mechanism in the CLI is not enough for contemporary parameterization design - although we also Support them.

The above points will have related discussions in our series columns. In particular, we will explain the templates and generic mechanisms in C / CLI in detail.

The fourth design level of C / CLI is that it selects "Integrated" rather than "replace" strategy, which is unique to C and some languages, and some other languages ​​do not do this, such as Visual Basic is taken. "Replace" strategy. A legal C program can be compiled smoothly through C / CLI and can run normally. We think this is a basic requirement for our programmers. Talking about the fourth design level of C / CLI, what does this mean? It indicates that we have an in-depth integration of C / CLI language specification and ISO-C . For example, in addition to our extended support set makes it applicable to unified CLI type systems, the standard conversion set of expression evaluations is the same as that of the overload function and ISO-C . When we introduce templates and multi-inheritance mechanisms, we also applied the same extension strategy. These are some abstract parts in language, and in some extent we have made their behavior more intuitive, eliminating the need for programmers in depth algorithm details. But we will still spend the pen in the series column to pay attention to some major changes, such as processing of literal strings.

In the future version of C / CLI, we want to provide a more seamless integration for local types and CLI types. In the current implementation, there are still many barriers that cannot span. For example, we can't declare a local instance object in a CLI class; in contrast, we must declare a pointer to that local object, then process it in the CLI class constructor / destructor pair Memory allocation and release. We hope to handle them in the future. Similarly, if you can easily write the following code, it is better:

N ^ n = gcnew n;

R * pn = new r;

An a local class is transparently placed in the hosted stack of garbage collection control, and a CLI reference type is transparently placed in the local heap and makes them operating normally. These are some of our ideas and vision for the future of C / CLI. As these ideas, we will also discuss them in our columns.

Finally, answer a question that everyone is often asked, "Why do I learn C / CLI?" The primary reason is that C / CLI will provide a first equivalent entry visa for the dynamic component programming model of the CLI. If you think that this will become more and more important as an important programmer, and if you are a deeper programmer, then C / CLI is a language tool you want. If you don't like some places, or find something difficult to express, please tell us. We represent a dynamic programming community, and C / CLI will continue to advance.

Before the C / CLI, if we hope or need to work in the dynamic programming field represented by the CLI, then we can only give up using C [Translation Imposion 3], which means we will give up our existing codebook and coding experience. After C / CLI, we have a transplant path along C up. This is the first reason for learning C / CLI.

The second reason for learning C / CLI is that it allows us to access the entire CLI framework class library, including user interfaces, threads, networks, xml, ado.net, ASP.NET, and Web services this wide seductive world. In addition, in the upcoming WinFX, a class library system that encapsulates the entire operating system (including the application and its execution space [translation 4]) are also included under the CLI gate.

[Translation 1]: STAN LIPPMAN

In the process of this article, I found that Stan always used a "she", "her", was very confused, because I felt very unfair, But I always feel that Stan is interested. Finally, I decided to ask STAN asking us to do this. Sure enough, Stan's answer is that everyone habits "HE" is a manifestation of male-to-listedists, as if a programmer, everyone thinks is male. He does not agree with this view, I deliberately reserved the intention of "she" and "her" in the translated text, because he opposed the old suit. At the same time, two female jeans in two computer areas: one of the pioneers of the software industry, the founder of the assembly language, Dr. Grace Hopper, and Ms. Goldberg, a heavyweight expert in the SMALLTalk field. I hope that Stan's good intentions can encourage more female programmers to read our columns J?

BACK

[Translation 2]: Single root class is a reflection to provide support mechanisms to reflect a form of Handle to maintain type information. For example, in ISO-C , such a Handle requires a virtual table to support. If there is no virtual table, it cannot support RTTI, which makes ISO-C are relatively weak. However, the CLI uses a Handle to maintain type information in a public Object Header, which is subtly solved the problem of runtime type discovery. This public Object Header will eventually lead to all types of all types - if not deliberately hidden the base class.

BACK

[Translation 3]: The author does not consider Managed C because C / CLI is the second edition of Managed C .

BACK

[Translation 4]: The "Performing Space" here refers to some of the foundation constructs at the application runtime, such as assemblies, application domains, etc.

转载请注明原文地址:https://www.9cbs.com/read-70796.html

New Post(0)