Re-learn. Net [5] -- multi-language support for CLR

Source: Internet
Author: User
As we all know, CLR supports a variety of languages, including C #, VB. NET, and so on (to be exact, it should be that all languages can provide compilers to run on CLR ). To support multiple languages, CLR must establish a mode so that various languages can easily run on it. Although the syntax of various object-oriented languages is different, their core semantics is similar. Therefore, CLR uses this point, and all its content is centered around the type. The common type system cts of CLR is used to describe the type definition and behavior.
In short, CTS defines some types, which are divided into two types: Value Type and reference type. Value types include int32, Boolean, and structure, which are allocated on the runtime stack. Reference types include class, interface, array, and so on, which are allocated in the managed heap (I believe that people who have learned oo will not be unfamiliar with this ). Each type may have some members (0 to N), including fields, methods, attributes, and events. At the same time, each type uses some access control permissions, such as public and private. In addition, CTS also specifies some rules, such as: All types must be inherited from objects, and single inheritance is supported. All these type settings and Rules constitute CTS. Once a language is compiled, the CLR can run as long as it meets the CTS requirements. Therefore, to run a language on the CLR, it must comply with the rules and restrictions of CTS (for example, if C ++ needs to compile and run on the CLR, it must change its multi-inheritance mode ).
At the same time, CTS is so huge that no language can support all its features (including C # and VB), and CLR does not have this requirement. This will cause a problem. How can libraries written in one language be called by other languages? Assume that a language supports uint64 and implements a library with the public int64 getint () method (). At this time, another language is Program This method is intended to be called in the design, but it does not support uint64, so that it cannot be used at all. This is obviously different from the concept of CLR multi-language support.
To achieve multi-language communication, a general language specification CLS is also required, which is a subset of CTS. All languages running on CLR must fully support Cls. For example, CLS has int16 but does not require uint64 (supported in CTS). To run a language on CLR, it must support int16, but not uint64. This also tells us that if you want your class library and framework to be called by all languages that support CLR, you must only publish interfaces in CLS specifications, of course, you can use all types supported by CTs for programming internally.
To put it bluntly, CTS is a day. It embraces everything. CLS is a place and must stand on it. Most languages are between the two (CLS superset, a subset of CTS). It can be said that it is awesome (Sorry, it is a bit bad, please bring your own garbage bag ^_^ ).
Every time I think about this question, I have a doubt. Is it true that C # and VB. NET must have the same twins? (although their syntax habits are different, the supported features and features are almost like dead ends )? Of course, Microsoft has commercial considerations, but I still miss the simple VB era. I always think that the VB. NET syntax should be simpler, better entry, and more efficient in development. It is said that the feature set of VB. NET and C # Will be separated in the future. Well, I hope this is true.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.