Python comparison operators chaining

I was browsing StackOverflow and I’ve discovered some confusion about an apparently simple Python expression:

expected == result is not None

How would you evaluate that ? Something is fishy about checking if True/False is not None isn’t it ? Well I made the same mistake and assumed some parentheses like this, but it’s wrong!

(expected == result) is not None

After I’ve read the documentation more carefully I’ve found that, although they are both comparison operators and have the same precedence, they also chain together as in: “x op1 y op2 z” is evaluated like “(x op1 y) and (y op 2 z)”. So the expression above is evaluated as follows:

(expected == result) and (result is not None)

Now that makes more sense! As a conclusion, don’t chain comparison operators in Python when it’s not obvious that they will be chained together. Choose the more obvious readable version or you will shoot somebody in the foot … maybe even yourself ;)

Bitcoin: the money revolution

April 8, 2013

I’ve been looking all day for various information about Bitcoin and other crypto-currencies and I’m fascinated by the entire fenomen. In an attempt to revolutionize the money system as we know it (or don’t know it) Satoshi and the people inspired by him have started creating a plethora of tools that allow experimenting with various economic and cryptographic models. Is a deflationary monetary system sustainable or is inflation a necessary evil ? Will a huge transaction chain be sustainable in the long run or will the distributed system fail due to security or speed issues ? Will the people use it as a value store (speculators) or value transfer (buying/selling products or services) ? Will the speculating hype raise awareness about the currency or kill it by making it too volatile?
Just wait and see what happens to Bitcoin…

Gamification: what makes games and apps addictive ?

When I was young I liked to play all kind of games, as any kid, but specially video games. I was addicted to it and I loved that addiction. I’ve started by running away from crazy birds in Chuckie Egg (on a ZX Spectrum) and helping Dizzy find his way home, then I continued with other games on the PC. I still remember a ~50 hours marathon of Settlers and countless all-nighters of Starcraft with my friends. Later my interests have changed and instead of playing the games I’ve started creating my own, but that’s another story.
Today, after many years, I realize that I haven’t played any games in a while and that’s a shame since I’m very interested in the concept of gamification in the context of applications but also life, e.g. forming new habits with Lift or waking up early with WakeUp.
So I went to the Android store and downloaded one of the recommended games, Beach Buggy Blitz and I’ve started playing it while observing my addiction building up:
  • the starting point was that I like driving video games (Carmagedon, I love you) and also steering using the accelerometer was fun
  • the first challenge was getting the hang of the accelerometers’ lack of sensitivity without getting dizzy
  • then I got better at driving the buggy and I was starting to enjoy my new skills so that kept me going
  • because I was getting better I’ve started passing more checkpoints and discovering more of the beutiful and unpredictable scenary before my time ran out, but I wanted more!
  • I could also get better with power-ups and “cheats” such as “dropship 2 km ahead” so I’ve played more to get more power-ups; the alternative was paying with my credit card for them but I didn’t like to give up the challenge
  • the first 600 points were given for free after the first game to “give me a head start” e.g. first drug doze is free
  • I was anxious to find out what the easily bought power-up did so I kept playing … only then I realized how hard I have to work to get the second one!
  • at that point I even considered buying the “collect 2 coins for 1″ cheat with real money as i did not see it as a cheat but it increased efficiency and less wasted time for me was worth much more then $2
  • eventually I stopped playing when the power-ups got too expensive and the return value was no longer significant or fun
Conclusion is that at the end, 3 days later, I forgot why I even started playing (steering a wheel with the accelerometer) and got in a loop of running for coins, getting power-ups to get more coins to get more cheats to get more and more of what I did not even need, just like in real life! Congratulations to the game designers for successfully messing with my brains by creating an artificial scarcity of game coins and time but also rewarding me with power-ups and a fun game experience.
I eventually didn’t like this addiction so I dropped it … but I have others addictions left like computers in general and dancing argentine tango.
What are you addicted to ? Games ? Sex ? Life ? … and how did you get that addiction ?