I love learning new programming languages. I’ve been reading Bruce Tate’s “Seven Languages In Seven Weeks” with the hope of getting a flavour of all the different paradigms on offer. It is impossible to learn a new languages by simply reading – you have to get stuck in with the code to gain a true understanding. Mr Tate gives us the opporutunity to dive into some practice examples he has thoughtfully prepared for us. They are a good start, but i like something more involved to move onto.
And that’s where poker comes in. Texas Hold’em may or may not be your cup of tea, but it is a game to perfectly test your understanding of the languages you are writing in.
Just look at the different elements that come into play:
- Scoring hands. This is a non-trivial task that is on the surface, quite straightforward with OO. But scoring hands is perfect for functional languages. For extra difficulty, remember – Ace is both high and low!
- Who wins what? With varying players in the game, and varying amounts in the pot, this could get tricky!
- Performance. Ok, so you’ve worked hard on your perfect card-scoring functions. Now we can really test how well you’ve done by asking “how many hands can we score per second?”.
- DSLs. Perhaps the language you are using is good for developing DSLs. Could you write a DSL that mimics a hand of poker? One round? Or even an entire poker game? Something such as the following would be a start (I’m pretty sure Scala’s implicit type conversions will perform this miracle):
“AC QH 10S 2D 4C 8D AD” vs “3S 10C 3C 5H QD QS 7S”
- AI. If you’ve played poker, you know it can be an infinitely complex game of deep strategy. But even a simple A.I. bot can give a player a good run for his money. Start with the basics (hand strength, pot odds, outs) and go from there.
- Immutability. Can you complete your program whilst keeping it completely immutable? I don’t mean scores, chips, etc. I mean, can you avoid mutable data structures, state-ful functions, etc.
Once I’ve written a basic poker engine once, it becomes easier to use it as a comparison between languages. I have a firmer understanding of which languages perform better in which circumstances. Oh, and it’s definitely more fun than writing business applications!