What is typing style?

Asked

Viewed 2,209 times

15

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

static and dynamic, strong, safe and insecure, nominative, partially inferent

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

  • Related: http://answall.com/questions/96722/qual-a-diff%C3%A7a-among-the-concept-of-typing-est%C3%A1tica-e-din%C3%A2mica-e-o-concept-de

2 answers

14


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

Static X Dynamic

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

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

Has been answered in depth in What is the difference between a static and dynamic programming language?

Forte X Fraca

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

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

It is common to have both in the language, but the classification is given 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 some guy can be treated like string, any type can be treated as object or a direct or indirect ascendant, as is the case with the object. But as it is done safely, in general it is considered only that the strong is adopted.

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

Segura X Insecure

Here determines whether a type can be used wrongly or not. Not necessarily whether it is the right type or not, it can be any form of error. We can’t always classify language as one way or another.

Almost every language has some type of insecurity. In general, languages call themselves safe for marketing purposes. The classification ends up being subjective. If the program can break without further explanation, there may be security issues by improper use of the types, or other failures, then it is not type Safety. It is very difficult to make a language that guarantees this always, and even more being flexible enough to become viable.

It’s a mistake to think that type security and strong typing are the same thing.

See more and yet.

Nominal X Structural

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

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

But one might dispute this by saying that actually the guys are always nominal and C# uses only one trick. So I don’t know what the line is because all we see in high-level languages are tricks to not expose the exact mechanism.

Manifesta X Inferente

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

Structural types obviously can only be inferred.

C# can infer by assigning local variables, as long as it is easy to detect that something is inambíguo, so it does not detect the type of a delegate. In other locations and situations it does not detect, especially by use. C# detects the return type and parameters of Amble, which hinders the delegate’s inference. The inference of local variables is detected by var.

6

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

Strong typing

Almost a synonym for safe typing. The types of all things need to be respected and you can’t cheat any kind (that’s it), Haskell and Python fit the definition.

Weak typing

It is quite understandable: you can bypass 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.

Safe typing

Whenever you try to use an incorrect type at some time the compiler/interpreter needs to treat and give you some error message.

Word typing

Types are equivalent if their names are equal: int with int, float with float, struct Ast with struct Ast etc.

Partially inferent

It concerns the ability of language to deduce the type of an element without needing you to specify explicitly.

  • 3

    Vitor, add this to the Wikipedia page tmb. It will be nice! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.