Questions? Feedback? powered by Olark live chat software
Alin Pandichi Software Developer at MozaicLabs

Covariance and contravariance. Say what?!

Make sense of how the concepts of covariance and contravariance are used in typed programming languages.

While merrily browsing the Internet and reading technical articles about programming, you may encounter the terms of "covariance" and "contravariance." These sound spooky enough to make you consider closing the tab and forgetting all about it, as if it were a bad dream. It doesn't have to be that way!

These two terms are actually abstract mathematical concepts that are used in probability theory, statistics, theoretical physics, category theory and (you guessed it!) computer science. Each aforementioned field has a certain definition regarding what covariance / contravariance is. Each definition may or may not have a degree of similarity to the other definitions in the other fields.


During this talk, we'll try to make sense of these things, together. We'll lightly touch upon what covariance and contravariance means in a couple of applied mathematical scenarios (Don't worry, we won't be talking about functors!). Then, we'll see how these concepts are used to describe subtyping relationships in programming languages such as Java and C#. There will be code examples, of course!