Talk
Not Quite My Type Duration 40m

Using PHP’s type system to make impossible states truly impossible.

Have you ever applied a negative discount to a customer’s order? Of course you didn't, because that wouldn't make any sense. But does your code allow it? Does the method to apply a discount accept any old integer or float? If it does, you probably had a check at the very top of that method to validate that the passed discount is actually valid, i.e. greater than zero. Wouldn't it be nice, if it wasn't even possible to call that method with an invalid input? After all, negative discounts don't make any sense. Like, by definition.

In this talk we explore different ways of modeling the data that flows through your application to ensure that states that should be impossible are actually impossible at the type level. Not only will this make your code more expressive and less prone to errors. It also greatly increases how well your IDE or static analysis tools understand your code.

This talk at your event?

Contact the speaker