6

I was wondering why the terms Covariance and Contravariance are named like that in programming domain. Usually one hears these terms in Probability theory or Statistics indicating the spread of quantities being measured with respect to the Mean.

  • What is the idea for borrowing these terms from Statistics?
  • How does these terms describe this spread in programming domain?
  • What would be the Mean in programming domain?

I know that Covariance is the ability to assign an expression of a more specific type to a variable of a less specific type but, is there another interpretation for this?
Examples relating both these domains would be helpful.

zizouraj
  • 473
  • 2
  • 11
  • Variance is just "difference" - in stats it's related to how much the samples vary from the mean; in programming it's how types vary (whether you can use subtype/supertype relationships etc). – Jon Skeet Aug 27 '14 at 14:24
  • 1
    Why do you think it comes from `Statistics`? It comes from `category theory` according to [wikipedia](http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29#Origin_of_the_term_.22covariance.22). – Jesse Good Aug 27 '14 at 14:40
  • This is why I like the `in T` / `out T` decision in C#; it is pretty intuitive that they mean, without having to remember which is which – Marc Gravell Aug 27 '14 at 14:40
  • This question appears to be off-topic because it is about etymology rather than a specific programming problem. – Servy Aug 27 '14 at 14:44
  • @Servy Though I do want to know the answer. Maybe a move to programmers SE? – xDaevax Aug 27 '14 at 14:45
  • @JesseGood These terms makes sense to me in statistics, which describes the spread of the data from Mean. Now my question is how should I make sense of these terms in Programming domain. – zizouraj Aug 27 '14 at 14:45
  • @xDaevax etymology questions are not on topic on programmers either. – Servy Aug 27 '14 at 14:46
  • 1
    It should help understanding the concepts, right? I have problems understanding programming concepts, too..so this is fine by me. – TaW Aug 27 '14 at 14:54

1 Answers1

2

I'm not a mathematician, so I wouldn't try to answer the question my own, but you can find a wonderful explanation to your question on Tomas Petricek's blog.

He explains in detail there how covariance and contravariance in programming are related to pure mathematical category theory.

alaendle
  • 21
  • 1