How to think like a poker player (or a programmer.)
At the Poker Table...
I'm playing the 2/5 Texas Hold'em game at the Venetian in Las Vegas. I haven't had many cards to play, and right after I decide to go home, I'm finally in a hand. A young 20 something male grabs 3 stacks of red chips and nonchalantly says "Three hundred dollars" after the final card is dealt. My action will complete the hand. The options are "Do I fold, or do I call?" If I call and win, I'm will win the last $300 plus the $200 that's already in the pot. If I call and lose, I just wasted an extra $300. Folding is the safe play here... but something doesn't seem right.
This is why poker has been said to be "hours of boredom, and moments of sheer terror."
My hand is very weak. But that's only half the story. What's important is what cards this may player hold. I look at the player. He looks right into my eyes with a veiled threat. I think about how the whole hand played out, the entire process. I combine all the variables and decide to say those dreaded words, "I call."
Thinking logically through each step, is something both programmers and pro poker players have to do. In poker it's important to be able to see through your opponent's eyes and add together all of the different variables. "Why did he bet this specific amount here, why did he stare into my eyes, what cards does he think I have, why did he stop chewing his gum when I asked him a question"... The list can go on a long time.
For programmers, while it's not exactly the same, it's very similar. Here's a rather simple, but fun, problem I had to figure out on The Error Logs:
"How do I make images that are published by a blog user shrink to fit the screen?"
- I'm using bootstrap so if we add a class of 'img-responsive' to each image, they will automatically shrink to fit.
- I'm not going to make the user manually add a class every time (lol), so it will have to be done automatically.
- In order to grab each image, I'll first have to access every post that is displayed.
- Each post has the same class of 'post'. I'll use that to grab all of them, then use a loop to get access to each specific post.
- Now in each separate post there may be more than one image. So I'll need a second loop to go through those.
- Add the class to the image(s) inside of the loop
All this logical thinking resulted in this:
The funny part is I can't even remember why I have that line "typeof images[x] !== "undefined".... Which is bad lack of commenting on my part. Live and learn. I'm sure it's serving a purpose so I'm not going to touch it. ;)
Beyond Code... Beyond Poker
Personally, I've found this process of going through each step logically to be life-changing. As I did it more and more (it first started with poker 11 years ago), I found it began to trickle down into other areas of my life. It's easier for me to take a dispassionate view of things going on around me, allowing me to make better decisions. I'm no Spock just yet but my world view has changed because of it.
A pretty cool thing to happen from just playing poker and coding.
As for that Hand
I won. My opponent threw his cards in disgust at the table, emoting loudly about how stupid a call that was.
He wasn't thinking logically.