good-design-and-type-safety-in-yahtzee
CRANK

good-design-and-type-safety-in-yahtzeeMark Dominus wrote an article asking how to take advantage of Haskell’s type safety in a simple dice-rolling simulation function for the game Yahtzee. He added wrapper types so that one cannot mistakenly apply the function to values that merely have the correct type “by accident”. He says the result is “unreadable” and “unmaintainable”. It certainly doesn’t look nice! I’d claim it’s not even of much practical safety benefit (although I suppose that depends on what the rest of the program looks like).Mark saysI don’t claim this code is any good; I was just hacking around exploring the problem space. But it does do what I wanted.But we can’t just expect to sprinkle type safety on a bad design and get something good. Type safety and good design are qualities that evolve symbiotically. By using type safety merely to make things safer for our callers we miss out on a host of benefits. Type safety should be used to guide us in the design of …

h2.jaguarpaw.co.uk
Related Topics: