What is typing style?

12

On Wikipedia, on the C # page says about the "typing style" of the language:

  

static and dynamic, strong, secure and insecure, nominative,   partially inferred

What is typing style? What do the above terms mean?

    
asked by anonymous 16.03.2017 / 04:50

2 answers

9

In fact the most appropriate term is the type system adopted by language. Each rating has at least two forms, and usually one opposes the other, but it is possible to adopt both with at least one of them optional.

Static X Dynamics

It is the ability of a given or variable / constant to be checked at compile time if it is what is expected in that context. Also has to do with the ability to change the type after declared. In static typing can not be changed and everything is checked at compile time, since in dynamic this does not occur and it is necessary to make sure everything is right, in many cases checking before using a given data.

C # uses static typing, but can optionally use dynamic with dynamic . This was covered in Why are not the other types of variables replaced by dynamic in C #? .

This has already been answered in depth in What's the difference between a static and dynamic programming language?

Strong X Weak

It's not a very official classification, and even its definition is confusing, so often it's confused with static and dynamic, but it's a mistake to think it's the same thing.

Strong typing prevents a data of one type from being treated as if it were of another type while the weak one allows.

It is common to have both in the language, but the classification ends up by what is predominant, perhaps even by not having a formal definition.

C # uses strong and weak typing actually. A short can be treated as int . Often any type can be treated as string , any type can be treated as object or a direct or indirect ascendant, as is the case with object itself. But as it is done safely, it is generally considered only that the fort is adopted.

The terms have already been answered in depth in another question .

Unsecured X

Here you determine whether a type can be used wrongly or not. Not necessarily whether it's the right kind or not, it can be any form of error. We can not always classify language as one way or another.

Nearly every language has some kind of insecurity. In general, the languages are called safe for the sake of marketing. The ranking ends up being subjective. If the program can crash without further explanation, there may be security problems due to improper use of the types, or other faults, so it is not type safety . It is very difficult to make a language that guarantees it always, and even more being flexible enough to become viable.

It is a mistake to think that type security and strong typing are one and the same.

Nominal X Structural

We are talking about the ability to identify the type of data by its manifest name or structure, or by its members.

C # uses the nominal typing, but more and more the structural one is being adopted. Already it happened with an anonymous types and more now with tuples that are inherently anonymous.

But someone can dispute this by saying that in fact the types are always nominal and C # uses only one trick. Then I do not know what the line is drawn because everything we see in high-level languages are tricks not to expose the exact mechanism.

X Inferential Manifesta

We're talking about how types are declared. If they must be explicit, that is, you need to type the type name to declare it. If they can be implicit, that is, the compiler can detect the type by its assignment or use.

Structural types can only be inferred.

C # can infer by allocating local variables, as long as it is easy to detect that something is unambiguous, so it does not detect the type of a delegate . In other places and situations it does not detect, especially by use. C # detects the return type and lambda parameters, which makes delegate inference difficult. Inheritance of local variables is detected by var .

    
16.03.2017 / 11:35
5

The style of typing is nothing more than the classification of the type system of some language, it can be the union of more than one of the categories:

Strong typing

Almost a synonym for secure typing. The types of all things need to be respected and you can not circumvent any type (that's it and that's it), Haskell and Python fall into the definition.

Poor typing

It is quite understandable: you can circumvent the type system, example is to convert a pointer of type struct Node to int, in C.

Static typing

It means that all type checking is done at compile time, a good example is the C language, which can figure out the type of all things before generating the executable.

Dynamic typing

Type checking is done at runtime, Python is a good example.

Secure typing

Whenever you try to use an incorrect type at some point the compiler / interpreter must handle and give you some error message.

Named Typing

Types are equivalent if their names are the same: int with int, float with float, struct ast with struct ast etc.

Partially inferent

If it concerns the ability of language to deduce the type of an element without specifying explicitly.

    
16.03.2017 / 05:47