OdeToCode IC Logo

Looking Back: Python

Thursday, July 11, 2013

Rabbints, Campfires, PythonTrue story: My first use of Python was a little over 10 years ago.  I used Python to prevent rabbits from running into campfires and injuring themselves.

Of course the rabbits were virtual, as were the campfires. I was working with a team to create MMORPG middleware, and Python scripts were the brains for some of the lesser NPCs.

I’ve been working with Python again recently.

class Cart:

    def __init__(self):
        self.contents = dict()

    def process(self, order):        
        if order.add:            
            if not order.item in self.contents:
                self.contents[order.item] = 0
            self.contents[order.item] += 1

        if order.delete:
            if order.item in self.contents:
                self.contents[order.item] -= 1
                if self.contents[order.item] == 0:
                    del self.contents[order.item]

    def __repr__(self):
        return "Cart: {0!r}".format(self.__dict__)

It’s interesting how my opinion of Python has changed. Ten years ago the majority of my programming experience was with C, C++, and Java. My thoughts on Python were:

1. Using indentations to control block structure was weird, considering white space was insignificant everywhere else.

2. Tuples were useful.

3.  Double underscores look cool

Todays thoughts:

1. Tuples are still useful, but the REPL perhaps more so.

2. How did I miss lambdas, generators, map, filter, and reduce?

3. Double underscores are ugly, but the absence of { and } and is beautiful.

I like Python, it’s a great language. I have a better appreciation for its features today than I did 10 years ago.