This is a Wikipedia user page. This is not an encyclopedia article or the talk page for an encyclopedia article. If you find this page on any site other than Wikipedia, you are viewing a mirror site. Be aware that the page may be outdated and that the user whom this page is about may have no personal affiliation with any site other than Wikipedia. The original page is located at https://en.wikipedia.org/wiki/User:Cl%C3%A9ment_Pillias. |
Pages that I expanded
edit
Sandbox
editIn Computer Science, variance properties describe how some type operators (i.e., functions acting on types in the type system of a given programming language) behave relatively to some order relation for the types, which is usually the subtype order defined by inheritance in object-oriented programming language. A type operator is said to be covariant if it preserves this order, contravariant if it reverses it, and invariant otherwise.
Variance properties can be specified in the programming language for some type operators, most often for operators allowing the construction of new types from known ones (such as arrays, pointers, etc.), or for type qualifiers (such as const). On the other hand, some programming language allows the programmer to create such type operators via generic programming and to specify their variance properties.
The concept of variance is also applied to operators that do not appear explicitly in the programming language but reflects how the compiler or interpreter should work, such as getting the return type of a given function from the type of one of its arguments; or getting from a given class the type of its member with a given name. When the variance of such artificial type operators is defined in the programming language, it sets some aspects of the language, such as the acceptable signatures of a method overriding another one.
When a variance property is set, it usually allows programs to be more concise (by reducing the number of explicit type conversions) and easier to understand (by allowing the reuse of identifiers when it makes sense). It can also help the developer to understand some high-level concepts of the language.
(but other order relations can be considered, such as the more general one defined by the Liskov substitution principle.)