Wednesday, January 25, 2012

Python Patterns: Non-Empty Strings are True

The idiomatic way in Python of writing a non-terminating while-loop is:
    while 1:
or the (slightly slower) alternative:
    while True:
I saw a suggestion on the Python mailing list that I really like, which relies on the behaviour that non-empty strings are evaluated by conditions to be True and provides a self-documented truth-condition, which can note why the loop is non-terminating or what the break condition is.
    while "the program is running":

    while "data is still streaming":

    while "no one presses escape":

Wednesday, January 04, 2012

Where to begin?

My one and only resolution for 2012 is to stop talking about writing a game and actually do it, preferably before the Eschaton. This isn't the first time I've made this promise, however; in the past I've always rapidly hit the issue of having too much choice and not being sure how to progress. And this time isn't really any different.