a blog for those who code

Friday 1 August 2014

Definition of Common Type Specification (CTS) and Common Language Specifications (CLS)

In this post we will show you what is the definition of Common Type Specification (CTS) and Common Language Specifications (CLS).


The Common Type Specification (CTS)

To support multiple programming languages on a single CLR, the types of each programming language must be compatible. The binary compatibility between language types is called the Common Type System (CTS). Simply, types are the mechanism by which code written in one programming language can talk to code written in a different progrmming langauage. Its important for Language Interoperability.

The CTS performs the following functions :

1. It establishes a common framework that enables cross-language integration, type safety, and high performance code execution.
2. It defines rules that languages should follow, so that any language can run on a single CLR.

CTS also specifies the rules for type visibility and access to the members of a type. That means if a type is specified as public, it will be visible and accessible to any assembly whereas marking it internal will make it visible and accessible within the same assembly.

Note that language and behaviour are two different things, that means the syntax which you use for defining the type is different depending on the language but their behaviour will be identical regardless of the langauge because the CLR's CTS defines the behavior of the type.

Thre is one more CTS rule, that all types must inherit from a predefined type : System.Object. The Object is the root of all other types and therefore guarentees that every type instance has a minimum set of behavior.

The Common Language Specifications (CLS)

The Common Language Specification(CLS) is a fundamental set of language features supported by the Common Language Runtime (CLR) of the .Net Framework. Simply it means that when there is a situation to communicate Objects written in different .Net Complaint languages, those objects must expose the features that are common to all the languages.

Now we should know that whats the need of CLS when we have CTS. For programming languages to communicate effectively, targeting IL is not enough. There must be a common set of standards to which every .NET language must adhere.

Lets take an example, Objects are common to both language and its type safe as per the CTS but this Objects might have different meaning to two different languages, so we should have Common Language Specification(CLS) to understand that Objects and communicate accordingly.

Please Like and Share the Blog, if you find it interesting and helpful.

No comments:

Post a Comment