Covariance and contravariance, part 3: Covariance in interfaces

This article is the third in a series on covariance and contravariance: Covariance in arraysContravariance in interfacesCovariance in interfaces In the previous article I showed how an interface could be contravariant, meaning it is expecting a smaller type for something you pass it. In this article I will show how an interface can be covariant, … Continue reading Covariance and contravariance, part 3: Covariance in interfaces

Covariance and contravariance, part 2: Contravariance in interfaces

This is part two in a series about variance – contravariance and covariance. Arrays and listsContravariance in interfacesCovariance in interfaces In the previous article I introduced the concepts of variance and type size.  I also gave arrays as an example of covariance. In this article I’ll give an example of contravariance, and go into more … Continue reading Covariance and contravariance, part 2: Contravariance in interfaces

Covariance and contravariance – part 1: Arrays and lists

This post is the first in a series - for once I will split a large topic into a few small posts. The series is about covariance and contravariance, together known as variance. Arrays and listsContravariance in interfacesCovariance in interfaces Covariance and contravariance are terms I came across occasionally, and never understood properly. Having put … Continue reading Covariance and contravariance – part 1: Arrays and lists

Computer science while washing the dishes 1: The Queue

Calvin and Hobbes said that there’s treasure everywhere.  For a sad geek like me, there’s also computer science everywhere.  Doing the washing up the old school way involves a metaphor for the computer science concept of queue, if you think of people collaborating around the draining board.  Quite a lot of this is a statement … Continue reading Computer science while washing the dishes 1: The Queue